You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The @ImageMagick project is using https://github.com/google/oss-fuzz to find bugs in our own library and in libraries that we use. Attached is a test file that will result in an excessive memory allocation due to this line:
Adn this makes l_nb_tiles = 1337 * 48 = 64176. We don't know enough about the format but we suspect that a check could be added to do an early exit instead of allocation below
The file cannot be read with the master version due to stricter checks.
===========================================
The extension of this file is incorrect.
FOUND CFtl. SHOULD BE .j2k or .jpc or .j2c
===========================================
[INFO] Start to read j2k main header (0).
[WARNING] Unknown marker
[WARNING] Cannot take in charge mct data within multiple MCT records
[WARNING] Unknown marker
[INFO] Stream reached its end !
[ERROR] Stream too short
ERROR -> opj_dump: failed to read the header
That said the underlying problem still exist. OpenJPEG does validate that the number of tiles does not exceed the maximum allowed of 65535 (
I was wondering if it would be possible to know the minimum size of a tile and check if the input data is long enough.
I've managed to create a file of 65535x1 pixels with tiles of size 1x1, so 65535 tiles. Its size is just 3.6 MB, so this is not an effective way of avoiding the issue.
Our file is only 244 bytes and I was wondering the allocation could be moved to opj_jp2_read_header_procedure and do the allocation right before the return OPJ_TRUE;. And before the allocation you could even check if the stream is at least 64176 * number of bytes required for single tile.
Activity
rouault commentedon Apr 7, 2018
The file cannot be read with the master version due to stricter checks.
That said the underlying problem still exist. OpenJPEG does validate that the number of tiles does not exceed the maximum allowed of 65535 (
openjpeg/src/lib/openjp2/j2k.c
Line 2314 in 98cfdd3
dlemstra commentedon Apr 7, 2018
Sorry for not mentioning but we are using a clone of the master on a daily basis.
I was wondering if it would be possible to know the minimum size of a tile and check if the input data is long enough.
rouault commentedon Apr 7, 2018
I've managed to create a file of 65535x1 pixels with tiles of size 1x1, so 65535 tiles. Its size is just 3.6 MB, so this is not an effective way of avoiding the issue.
dlemstra commentedon Apr 8, 2018
Our file is only 244 bytes and I was wondering the allocation could be moved to
opj_jp2_read_header_procedureand do the allocation right before thereturn OPJ_TRUE;. And before the allocation you could even check if the stream is at least 64176 * number of bytes required for single tile.Check the number of tiles and components before OpenJPEG reads the heâĶ