Skip to content

fix(geotiff): Turn off HTTP request bounds checking - #527

Merged
kylebarron merged 1 commit into
mainfrom
kyle/request-outside-bounds
May 11, 2026
Merged

kylebarron merged 1 commit into
mainfrom
kyle/request-outside-bounds

Conversation

@kylebarron

@kylebarron kylebarron commented May 11, 2026 •

Copy link
Copy Markdown
Member

Closes #524.

image

cc @gadomski


Problem

The land-cover example fails on main with SourceError: Request outside of bounds (#524).

@chunkd/source-http derives source.metadata.size from the first range response, preferring Content-Range and falling back to Content-Length. In a browser, Content-Range is only readable when the server lists it in Access-Control-Expose-Headers — S3 does not by default — so the Content-Length fallback (the length of a single chunk, not the file) gets recorded as the file size. @chunkd/middleware's chunk layer then rejects any later read whose end is past that bogus size with SourceError: Request outside of bounds — which is exactly the leader-byte read TiffImage.getTileSize performs.

Why land-cover specifically? The NLCD COG is 160000×105000 px → ~64K full-res tiles, so its TileOffsets/TileByteCounts arrays alone are ~1 MB and push the whole IFD/tag section past the 1 MB mark. So even the coarsest overview's tile data lives past the first chunk, and the layer breaks on initial load. Other examples have small headers, so the data deck.gl reads at the initial coarse zoom is within the first chunk — they'd hit the same bug fully zoomed in (cf. developmentseed/stac-map#459), it's just less obvious.

Fix

Seed source.metadata in GeoTIFF.fromUrl so SourceHttp never records a size (it only fills in metadata while it's still null), treating the source as having unbounded length. This makes @chunkd/middleware's bounds check a no-op and stops cogeotiff's getMaxLength from clamping — i.e. it behaves like @chunkd/middleware did before the bounds check was added. No dependency changes, no extra round-trip.

Trade-offs: we lose @chunkd/source-http's ETag-changed-mid-read detection and the legit "don't read past EOF" guard — both edge cases, acceptable for a temporary patch. TODO: remove once the upstream @chunkd fix lands.

Tests

New regression test (packages/geotiff/tests/fromurl.test.ts) stubs SourceHttp.fetch to mimic S3-as-seen-from-a-browser (range GETs report Content-Length but no Content-Range), opens a fixture COG via GeoTIFF.fromUrl({ chunkSize: 1024 }), and asserts a header-source read near EOF doesn't throw. Confirmed red (Request outside of bounds from SourceChunk.fetch) → green.

pnpm --filter @developmentseed/geotiff test, ... typecheck, pnpm check, and the deck.gl-geotiff suite all pass. (The 17 integration-rasterio failures present on this branch are pre-existing — missing local .npy fixtures — and unrelated.)

🤖 Generated with Claude Code

…en't rejected

`@chunkd/source-http` records `source.metadata.size` from the first range
response, preferring `Content-Range` and falling back to `Content-Length`. In a
browser, `Content-Range` is only readable when the server lists it in
`Access-Control-Expose-Headers` (S3 does not by default), so the `Content-Length`
fallback — the length of a single chunk, not the file — gets recorded as the file
size. `@chunkd/middleware`'s chunk layer then rejects any later read past that
bogus size with "SourceError: Request outside of bounds". This broke the
land-cover example on load: its huge tile-offset arrays push the IFD section past
1 MB, so even the coarsest overview's tile data lives past the first chunk.

Seed `metadata` in `GeoTIFF.fromUrl` so `SourceHttp` never records a size (it
only fills in `metadata` while it is still null), treating the source as having
unbounded length. Temporary until the upstream fix lands.

Closes #524

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@github-actions github-actions Bot added the fix label May 11, 2026
@kylebarron kylebarron changed the title fix(geotiff): work around chunkd "Request outside of bounds" on browser CORS fix(geotiff): Turn off HTTP request bounds checking May 11, 2026
@kylebarron
kylebarron enabled auto-merge (squash) May 11, 2026 21:01
@kylebarron
kylebarron merged commit f750047 into main May 11, 2026
6 checks passed
@kylebarron
kylebarron deleted the kyle/request-outside-bounds branch May 11, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SourceError: Request outside of bounds

1 participant