Skip to content

[io] compute LZF image sizes in 64 bit before checking the payload - #6504

Merged
mvieth merged 1 commit into
PointCloudLibrary:masterfrom
aysha-afrah26:lzf-image-size-wrap
Oct 25, 2026
Merged

mvieth merged 1 commit into
PointCloudLibrary:masterfrom
aysha-afrah26:lzf-image-size-wrap

Conversation

@aysha-afrah26

Copy link
Copy Markdown
Contributor

AddressSanitizer, PCLZF depth image with width 65537 and height 65536:

ERROR: AddressSanitizer: heap-buffer-overflow
READ of size 2 ... in pcl::io::LZFDepth16ImageReader::read<pcl::PointXYZ> lzf_image_io.hpp:101

The LZF image readers check the uncompressed size from the file against getWidth () * getHeight () * N, but that product is computed in 32 bit. With 65537 x 65536 it wraps to 65536, so a small payload passes the check while the depth reader walks the full width and height and reads past the decompressed buffer. The Bayer reader hits the same thing inside DeBayer::debayerEdgeAware (debayer.cpp:441), and the RGB24 and YUV422 readers return a cloud whose width * height no longer matches its size.

Doing the comparison in 64 bit means a wrapped product can never match, so all eight read/readOMP checks reject the file before anything is decoded. I also sized the Bayer RGB buffer with std::size_t, since w * h * 3 can still wrap after the check. PCL.LZFImageWrappedDimensions in test_io.cpp covers all four readers: it hits the overflow above without the fix and passes with it, and the rest of test_io stays green.

The PCLZF readers compare the uncompressed size from the file against
width * height * bytes per pixel, with width and height also taken from
the file. The product is computed in 32 bit and wraps, so a header with
width 65537 and height 65536 accepts a payload sized for 65536 pixels.
The depth reader then walks the full image and reads past the
decompressed buffer, and the Bayer reader hands the full dimensions to
the debayer, which does the same.

Do the comparison in 64 bit so a wrapped product cannot match, and size
the Bayer RGB buffer with std::size_t.
@mvieth
mvieth merged commit 78bd1b8 into PointCloudLibrary:master Oct 25, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants