Skip to content

Support suffix reads in ReadOnlyZipStore and MemoryStore - #113

Open
konstibob wants to merge 1 commit into
mainfrom
claude/memorystore-ozx-sharding-9e5de4
Open

konstibob wants to merge 1 commit into
mainfrom
claude/memorystore-ozx-sharding-9e5de4

Conversation

@konstibob

@konstibob konstibob commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes BioImageTools/ome-zarr-fiji-java#140

When only part of a shard is read, the sharding codec gets the shard index with read(-indexSize), meaning "the last N bytes". FilesystemStore, HttpStore and S3Store handle that, but ReadOnlyZipStore passed the -N straight into zis.skip(), and MemoryStore into ByteBuffer.wrap().

Unit Test Created : a shard file is 1092 bytes and its index is the last 68. read(-68) should read from byte 1024 on. Before this fix, ReadOnlyZipStore tried to skip -68 bytes and crashed.

If an array is smaller than one shard in some dimension (z=112 with 192³ shards in the issue), it hits every read.

  • ReadOnlyZipStore and MemoryStore now turn a negative start into size + start.
  • New StoreTest.testGetSuffix checks read(-10) for all stores. The old test only read the tail with read(size - 10), so this case was never tested.
  • New ReadOnlyZipStoreTest.testPartialReadOfShardedArray writes a sharded array, zips it, and reads a sub-region. Without the fix it fails with exactly Negative skip value.

…tore

ShardingIndexedCodec reads a shard index located at the end via
store.get(keys, -indexSize), i.e. "the last N bytes". FilesystemStore,
HttpStore and S3Store handle a negative start, but MemoryStore passed it
straight to ByteBuffer.wrap and ReadOnlyZipStore to ZipArchiveInputStream.skip,
which throws "Negative skip value". BufferedZipStore delegates to MemoryStore
and was affected too.

As a result, any partial read of a sharded array (index_location "end") from a
zip archive failed, e.g. reading a boundary shard whose valid region is smaller
than the shard shape.

Convert a negative start into an absolute offset using the entry size, add a
StoreTest case for suffix reads for all stores, and an end-to-end test reading
a sub-region of a sharded array from a zip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@konstibob konstibob changed the title Support suffix reads in MemoryStore and ReadOnlyZipStore (fixes partial reads of sharded arrays in zips) Support suffix reads in ReadOnlyZipStore and MemoryStore Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OZX file not working

1 participant