Skip to content

Fix integer overflow in JPEG 2000 encode output buffer sizing#163

Open
osklu002 wants to merge 1 commit into
Efferent-Health:masterfrom
osklu002:fix/jpeg2000-encode-buffer-uint-overflow
Open

Fix integer overflow in JPEG 2000 encode output buffer sizing#163
osklu002 wants to merge 1 commit into
Efferent-Health:masterfrom
osklu002:fix/jpeg2000-encode-buffer-uint-overflow

Conversation

@osklu002

Copy link
Copy Markdown

img_size was accumulated in a uint, which overflows for images where width * height * precision * components exceeds 2^32 bits (e.g. RGB 8-bit images larger than ~179 megapixels). The wrapped value produced an output buffer roughly one tenth of the required size, causing opj_encode to fail with "Unable to JPEG 2000 encode image".

Accumulate in ulong instead and clamp the requested buffer length to the maximum array length.

img_size was accumulated in a uint, which overflows for images where
width * height * precision * components exceeds 2^32 bits (e.g. RGB
8-bit images larger than ~179 megapixels). The wrapped value produced
an output buffer roughly one tenth of the required size, causing
opj_encode to fail with "Unable to JPEG 2000 encode image".

Accumulate in ulong instead and clamp the requested buffer length to
the maximum array length.
@osklu002

Copy link
Copy Markdown
Author

This adresses #131

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.

2 participants