You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
probeDecompressedSize treats custom codecs as uncompressed, returning the compressed size #5
probeDecompressedSize (src/get-worker.ts:301) decides whether a chunk is compressed by matching codec names against a fixed list of eight compressors. Any codec outside that list is treated as uncompressed, so the function returns rawBytes.byteLength — the compressed size — as the decompressed size.
For image codecs such as imagecodecs_jpeg2k (and HTJ2K variants) this is wrong by the whole compression ratio, and the bad number is then fed to inferChunkShape.
Where
src/get-worker.ts:318:
consthasCompression=codecMeta.codecs.some((c)=>{constname=c.name.toLowerCase()return(name==="gzip"||name==="zlib"||name==="blosc"||name==="zstd"||name==="lz4"||name==="bz2"||name==="lzma"||name==="snappy")})if(!hasCompression){// No compression codec — raw bytes are the decompressed datareturnrawBytes.byteLength// :336}
Codec ids that miss the list and are affected in practice.
Why it matters
The function has a correct step-4 fallback immediately below — a full decode through the codec pipeline, which would handle any codec. It is unreachable for an unrecognised codec, because the step-3 check short-circuits first.
Downstream in probeActualChunkShape (:574), the bogus size becomes actualElements = compressedBytes / bytesPerElement, which will not equal metaElements, so every read takes the mismatch branch:
up to 5 extra store.get round-trips validating inferred candidates (:620-634), and
a console.warn on every array, and
if no candidate validates, probeActualChunkShape returns candidates[0] unvalidated (:637-643) rather than the metadata shape — so a bogus chunk shape can be adopted, not merely warned about.
It is often harmless in practice (a compressed length rarely factors into plausible candidates, and an empty candidate list does fall back to metadata at :611), but the failure is silent when it isn't.
Suggested fix
Invert the check: enumerate the codecs known not to change byte size (transpose and other array_to_array codecs, bytes/endian as array_to_bytes) and treat everything else as potentially compressed, letting it fall through to the existing step-4 full decode. That makes the fallback do the job it was written for and removes the need to keep an allowlist current as new image codecs appear.
probeDecompressedSize no longer matches codec names against a compressor allowlist. The check is inverted as suggested here: hasSizeChangingCodec allowlists the codecs known to preserve byte count (bytes, transpose, with the numcodecs. prefix stripped) and treats everything else — including imagecodecs_jpeg2k, HTJ2K variants, crc32c, sharding_indexed, etc. — as size-changing, so unrecognised codecs now fall through to the step-4 full-decode fallback instead of reporting the compressed length as the decompressed size.
Covered by the hasSizeChangingCodec suite in test/browser/chunk-shape-inference.spec.ts, including a JPEG 2000 / HTJ2K regression test.
Activity
thewtex commentedon Aug 13, 2026
Fixed by #9 (merged 2026-08-06, commits 44f7474 + 8429394).
probeDecompressedSizeno longer matches codec names against a compressor allowlist. The check is inverted as suggested here:hasSizeChangingCodecallowlists the codecs known to preserve byte count (bytes,transpose, with thenumcodecs.prefix stripped) and treats everything else — includingimagecodecs_jpeg2k, HTJ2K variants,crc32c,sharding_indexed, etc. — as size-changing, so unrecognised codecs now fall through to the step-4 full-decode fallback instead of reporting the compressed length as the decompressed size.Covered by the
hasSizeChangingCodecsuite intest/browser/chunk-shape-inference.spec.ts, including a JPEG 2000 / HTJ2K regression test.