Skip to content

fix BigTiff offset overflow - #3616

Open
bossie wants to merge 8 commits into
locationtech:masterfrom
bossie:fix_write_bigtiff_overflow
Open

fix BigTiff offset overflow#3616
bossie wants to merge 8 commits into
locationtech:masterfrom
bossie:fix_write_bigtiff_overflow

Conversation

@bossie

@bossie bossie commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Overview

Fixes offset overflow in full res BigTiffs. Manifests itself when the first overview already tips the image size over the 2^32 threshold.

Checklist

  • ./CHANGELOG.md updated, if necessary. Link to the issue if closed, otherwise the PR.
  • Module Hierarchy updated, if necessary
  • docs guides update, if necessary
  • New user API has useful Scaladoc strings
  • Unit tests added for bug-fix or new feature

Signed-off-by: Jan Van den bosch <jan@bossie.org>
Signed-off-by: Jan Van den bosch <jan@bossie.org>
}
}

it("should handle offsets greater than 2^32 without overflowing") {

@pomadchin pomadchin Jul 21, 2026

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.

Unfoturnately this won't get through the CI (OOO); I'm fine with ignoring this one for now to make sure CI is happy; or if there is a better way to test the changes that'd be great ofc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, having a tile this large in memory is undesirable. I'm sure it can be improved, let me take a look.

As for the actual test: I currently do this on my machine by invoking tiffinfo -s on the generated BigTiff and taking a look at the actual tile offsets. The reason I do it this way is because:

  • instantiating a geotrellis.raster.io.geotiff.SinglebandGeoTiff from it throws a java.nio.BufferUnderflowException;
  • unless I'm mistaken, I don't think Geotrellis even exposes the actual offsets.

That being said, invoking something "independent" like tiffinfo to check things could actually be an advantage but this obviously needs to be available in the build container. Is it feasible to to install an additional package? I think it came with package libtiff-tools.

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.

🤔 hmmm, or to make it easier for you we can just make this test 'ignored' for now and that's probably better; to not introduce this complex dep on the tiff info

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, TBH at this point the heavy lifting has been done and now it's just a matter of installing a package in the test image. I favored tiffdump over tiffinfo because its output was easier to parse; it is also in the libtiff-tools package.

@pomadchin pomadchin 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.

LGTM; I'll take another look ofc.

But also the CI won't be happy unfortuantely due to OOO errs.

val segments = geoTiff.imageData.segmentBytes
val segmentCount = segments.size
val segmentBytesCount = (0 until segmentCount).map(segments.getSegmentByteCount).sum
val segmentBytesCount = (0 until segmentCount).map(segments.getSegmentByteCount).foldLeft(0L) {_ + _}

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.

minor: {_ + _} => (_ + _)

val segments = geoTiff.imageData.segmentBytes
val segmentCount = segments.size
val segmentBytesCount = (0 until segmentCount).map(segments.getSegmentByteCount).sum
val segmentBytesCount = (0 until segmentCount).map(segments.getSegmentByteCount).foldLeft(0L) {_ + _}

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.

minor: {_ + _} => (_ + _)

bossie added 4 commits July 22, 2026 17:03
Signed-off-by: Jan Van den bosch <jan@bossie.org>
Signed-off-by: Jan Van den bosch <jan@bossie.org>
Signed-off-by: Jan Van den bosch <jan@bossie.org>
Signed-off-by: Jan Van den bosch <jan@bossie.org>
@bossie
bossie marked this pull request as ready for review July 24, 2026 07:38
bossie added 2 commits July 24, 2026 09:42
Signed-off-by: Jan Van den bosch <jan@bossie.org>
Signed-off-by: Jan Van den bosch <jan@bossie.org>
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.

2 participants