Skip to content

Read HDF5 filter ids as unsigned 16-bit values - #1625

Merged
lesserwhirls merged 1 commit into
Unidata:maint-5.xfrom
djkwon26s:unsigned-filter-id
Nov 23, 2026
Merged

lesserwhirls merged 1 commit into
Unidata:maint-5.xfrom
djkwon26s:unsigned-filter-id

Conversation

@djkwon26s

Copy link
Copy Markdown
Contributor

Thank you for the prompt review and merge of #1621, and for the follow-up on the zstd plan. As promised, here is the small separate PR for the unsigned filter id.

Part of #1620 (the "filter id parsed as signed short" side note).

Problem

HDF5 filter ids are unsigned 16-bit values, but the filter pipeline message reads them with readShort(). Ids from 32768 to 65535 (the range HDF5 leaves for unregistered filters) become negative:

  • Filters.getFilter looks up -25536 instead of 40000, so a registered provider is never found (UnknownFilterException: no filter found with id -25536).
  • In a version 2 message the name length field is present for ids >= 256, but id < 256 is true for a negative id, so the field is skipped and the rest of the message is misaligned (the filter parameters {7} were read as {458753}).
  • The older ucar.nc2.iosp.hdf5.H5header fails on the same files with ArrayIndexOutOfBoundsException: Index -25536 in getFilterName.

Change

  • H5objects.MessageFilter: compare the id as unsigned for the name length check; Filter.getId() returns the unsigned value.
  • Filters.getFilter: convert a Short id with Short.toUnsignedInt; other Number types use intValue(). The value stored under Filters.Keys.ID is still a Short, so existing providers and callers see the same type as before.
  • H5header.Filter: read the id with readUnsignedShort() into an int.

Tests

TestH5FilterIdUnsigned with two small files (11-13 KB) that use the optional filter 40000 with cd_values {7}, one with a version 1 and one with a version 2 filter pipeline message. They were made with HDF5 1.10.5 h5repack -f v:UD=40000,1,1,7 (the version 2 file with --low=1 --high=1). The filter was not available when they were written, so the chunks are stored unfiltered with the filter mask set and the data can be checked without a real filter. A pass-through test provider is registered for id 40000.

  • provider lookup with the id as read from the file ((short) 40000)
  • read of both files, values and filter parameters

Without the change all three tests fail; with only the name length check reverted, the version 2 test fails on the filter parameters. The parameterized TestN3iospCompare and TestCoordSysCompare also pick up the new files and exercise the old H5header.

./gradlew :cdm-core:spotlessCheck :cdm-core:testWithJdk25 passes locally except for two TestMFileOS tests that fail the same way on unmodified maint-5.x on Windows (path separators).

🤖 Generated with Claude Code

HDF5 filter ids are unsigned. Ids from 32768 to 65535 were read as
negative shorts, so the filter provider lookup failed, and in version 2
filter pipeline messages the name length field was skipped, which
misaligned the rest of the message. The old H5header failed with an
ArrayIndexOutOfBoundsException for the same files.

Refs Unidata#1620

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@lesserwhirls lesserwhirls left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution. This looks good to me.

@lesserwhirls lesserwhirls added this to the 5.12.0 milestone Nov 23, 2026
@lesserwhirls lesserwhirls added iosp: hdf5 hdf5 file format filters Issues related to filters labels Nov 23, 2026
@lesserwhirls
lesserwhirls merged commit 4cd317e into Unidata:maint-5.x Nov 23, 2026
15 checks passed
@lesserwhirls lesserwhirls mentioned this pull request Nov 26, 2026
5 tasks done
lesserwhirls added a commit to lesserwhirls/netcdf-java that referenced this pull request Nov 26, 2026
Fix integration test regression due to new test files introduced in
blosc2 compression PR (Unidata#1625)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

filters Issues related to filters iosp: hdf5 hdf5 file format

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants