summaryrefslogtreecommitdiff
path: root/src/lib/openjp2/j2k.c
AgeCommit message (Collapse)Author
2023-12-08Merge pull request #1490 from headshog/fix-j2kEven Rouault
Integer Overflow at j2k.c:3962
2023-12-08Merge pull request #1491 from headshog/fix-j2k-headerEven Rouault
Integer Overflow at j2k.c:11114
2023-12-08fix j2k.c:11114headshog
2023-12-08opj_j2k_merge_ppm(): avoid unsigned-integer-overflow at j2k.c:3962 (#1490)headshog
2023-12-08suppress warning during build using clangTomoaki Teshima
2023-09-23fix: use `opj_uint_ceildiv` instead of `opj_int_ceildiv` when necessarymayeut
There are a bunch of loc where we can see a usage of `opj_int_ceildiv`: ``` (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)a, (OPJ_INT32)b); ``` where a & b are `OPJ_UINT32`. This can lead to overflow/underflow for some a/b combinations. Replace those calls by `opj_uint_ceildiv` instead to always get a correct result. This also allows some valid single tile images with huge tile size to be decoded properly. Fix #1438
2023-03-09Merge pull request #1462 from sebras/masterEven Rouault
CMake: error out on warnings for strict/missing prototypes.
2023-03-09CMake: error out on warnings for strict/missing prototypes.Sebastian Rasmussen
And fix strict-prototypes/missing-prototypes warnings.
2023-03-07openjp2/j2k: replace sprintf calls with snprintfMark Mentovai
This makes it possible to build j2k.c without warnings using the macOS 13 SDK. Calls to sprintf are replaced with snprintf, passing appropriate buffer sizes. It doesn’t appear that any of the changed uses of sprintf were actually unsafe, so no behavior change is expected aside from SDK compatibility. The macOS 13 SDK deprecates sprintf as it’s difficult to use safely. The deprecation warning message is visible when building C++, but it is not normally visible when building plain C code due to a quirk in how sprintf is declared in the SDK. However, the deprecation message is visible when building plain C under Address Sanitizer (-fsanitize=address). This discrepancy was discovered at https://crbug.com/1381706 and reported to Apple with a copy at https://openradar.appspot.com/FB11761475. The macOS 13 SDK is packaged in Xcode 14.1, released on 2022-11-01. This also affects the iOS 16 SDK and other 2022-era Apple OS SDKs packaged in Xcode 14.0, released on 2022-09-12. j2k.c is visible to the Chromium build via PDFium, and this change is needed to allow Chromium to move forward to the macOS 13 SDK. This change is limited to src/lib/openjp2. Other uses of sprintf were found throughout openjpeg.
2022-08-11Cleanup code related to quality layer allocation, and add a few safety checksEven Rouault
2022-02-10opj_j2k_decode_tile(): avoid 'Stream too short' error in non-strict modeEven Rouault
2022-02-10Add support for partial bitstream decoding (#1407) (fixes #715)Robert Gabriel Jakabosky
Add a -allow-partial option to opj_decompress utility and a opj_decoder_set_strict_mode() option to the API Co-authored-by: Chris Hafey <chafey@gmail.com>
2022-01-23opj_encoder_set_extra_options(): add a GUARD_BITS=value optionEven Rouault
and add a -GuardBits option to opj_compress. The recently-released SMPTE DCP Bv2.1 Application Profile (link below) says that the number of guard bits in the QCD marker shall be 1 for 2K content and 2 for 4K content. This change allows the number of guard bits to be configured, so that users of openjpeg have the control they need to meet the specification. https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9161348 This is an alternative implementation of https://github.com/uclouvain/openjpeg/pull/1388 that keeps ABI unchanged.
2022-01-18Fix potential overflow related issues spotted by LGTM code analysis (#1402)Eric Harvey
2022-01-18opj_j2k_setup_encoder(): validate number of tiles to avoid illegal values ↵Even Rouault
and potential overflow (fixes #1399)
2021-12-05Fix singular/plural mismatchStefan Weil
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2021-12-05Fix some typos (found by codespell)Stefan Weil
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2021-10-21API: deprecate 'bpp' member in favor of 'prec'Even Rouault
in opj_image_comp and opj_image_comptparm structures. bpp was redundant with prec, and almost never set by the library, except by opj_image_create(). This change should hopefully not impact existing, working, users of the API, which should already have used prec to get things working. Fixes #1379
2021-09-25Added support for high throughput (HTJ2K) decoding.Aous Naman
There are a few limitations: - mixed mode (HT and regular code blocks) is not supported. - ROI in HT blocks is not supported. - Placeholder passes are not supported. - MultiHT sets are not support, only a singleHT set. - there are known issues with some compliance testing files related to the parsing of packet header.
2021-07-12Fix code formattingEven Rouault
2021-07-12opj_j2k_is_imf_compliant: Fix out of bounds access.Sebastian Rasmussen
Previously when mainlevel was parsed == 12 openjpeg would generate a warning, but then the sublevel value would be compared to an out of bounds element in the tabMaxSubLevelFromMainLevel array. From this commit OpenJPEG will only use mainlevel if in range.
2021-07-12opj_j2k_is_imf_compliant: Fix argument formatting for warnings.Sebastian Rasmussen
2021-06-07Add support for enabling generation of TLM markers in encoderEven Rouault
Support was already there, but restricted to Cinema and IMF profiles, and 255 tiles * Add -TLM switch added to opj_compress * Make opj_encoder_set_extra_options() function accept a TLM=YES option.
2020-12-02opj_j2k_write_sod(): avoid potential heap buffer overflow (fixes #1299) ↵Even Rouault
(probably master only)
2020-12-01opj_j2k_setup_encoder(): validate POC compno0 (fixes #1293)Even Rouault
2020-11-30Decoding: deal with some SPOT6 images that have tiles with a single ↵Even Rouault
tile-part with TPsot == 0 and TNsot == 0, and with missing EOC
2020-10-09Merge pull request #1253 from rouault/floating_point_irreversible_encodingEven Rouault
Single-threaded performance improvements in forward DWT for 5-3 and 9-7 (and other improvements)
2020-09-16Encoder: avoid uint32 overflow when allocating memory for codestream buffer ↵Even Rouault
(fixes #1243)
2020-06-23openjp2: Plug image leak when failing to allocate codestream index.Sebastian Rasmussen
This fixes issue #1259.
2020-05-20Merge pull request #1211 from sebras/masterEven Rouault
Add check to validate SGcod/SPcoc/SPcod parameter values.
2020-05-20opj_j2k_setup_encoder(): add validation of tile width and height to avoid ↵Even Rouault
potential division by zero
2020-04-21Add support for generation of PLT markers in encoderEven Rouault
* -PLT switch added to opj_compress * Add a opj_encoder_set_extra_options() function that accepts a PLT=YES option, and could be expanded later for other uses. ------- Testing with a Sentinel2 10m band, T36JTT_20160914T074612_B02.jp2, coming from S2A_MSIL1C_20160914T074612_N0204_R135_T36JTT_20160914T081456.SAFE Decompress it to TIFF: ``` opj_uncompress -i T36JTT_20160914T074612_B02.jp2 -o T36JTT_20160914T074612_B02.tif ``` Recompress it with similar parameters as original: ``` opj_compress -n 5 -c [256,256],[256,256],[256,256],[256,256],[256,256] -t 1024,1024 -PLT -i T36JTT_20160914T074612_B02.tif -o T36JTT_20160914T074612_B02_PLT.jp2 ``` Dump codestream detail with GDAL dump_jp2.py utility (https://github.com/OSGeo/gdal/blob/master/gdal/swig/python/samples/dump_jp2.py) ``` python dump_jp2.py T36JTT_20160914T074612_B02.jp2 > /tmp/dump_sentinel2_ori.txt python dump_jp2.py T36JTT_20160914T074612_B02_PLT.jp2 > /tmp/dump_sentinel2_openjpeg_plt.txt ``` The diff between both show very similar structure, and identical number of packets in PLT markers Now testing with Kakadu (KDU803_Demo_Apps_for_Linux-x86-64_200210) Full file decompression: ``` kdu_expand -i T36JTT_20160914T074612_B02_PLT.jp2 -o tmp.tif Consumed 121 tile-part(s) from a total of 121 tile(s). Consumed 80,318,806 codestream bytes (excluding any file format) = 5.329697 bits/pel. Processed using the multi-threaded environment, with 8 parallel threads of execution ``` Partial decompresson (presumably using PLT markers): ``` kdu_expand -i T36JTT_20160914T074612_B02.jp2 -o tmp.pgm -region "{0.5,0.5},{0.01,0.01}" kdu_expand -i T36JTT_20160914T074612_B02_PLT.jp2 -o tmp2.pgm -region "{0.5,0.5},{0.01,0.01}" diff tmp.pgm tmp2.pgm && echo "same !" ``` ------- Funded by ESA for S2-MPC project
2020-04-16Rename mis-named function opj_tcd_get_encoded_tile_size() to ↵Even Rouault
opj_tcd_get_encoder_input_buffer_size()
2020-02-12Implement writing of IMF profilesEven Rouault
Add -IMF switch to opj_compress as well
2020-01-11opj_j2k_update_image_dimensions(): reject images whose coordinates are ↵Even Rouault
beyond INT_MAX (fixes #1228)
2019-09-04openjp2/j2k: Validate all SGcod/SPcod/SPcoc parameter values.Sebastian Rasmussen
Previously the multiple component transformation SGcod(C) and wavelet transformation SPcod(H)/SPcoc(E) parameter values were never checked, allowing for out of range values. The lack of validation allowed the bit stream provided in issue #1158 through. After this commit an error message points to the marker segments' parameters as being out of range. input/nonregression/edf_c2_20.jp2 contains an SPcod(H) value of 17, but according to Table A-20 of the specification only values 0 and 1 are valid. input/nonregression/issue826.jp2 contains a SGcod(B) value of 2, but according to Table A-17 of the specification only values 0 and 1 are valid. input/nonregression/oss-fuzz2785.jp2 contains a SGcod(B) value of 32, but it is likewise limited to 0 or 1. These test cases have been updated to consistently fail to parse the headers since they contain out of bounds values. This fixes issue #1210.
2019-09-04openjp2/j2k: Make comments adhere to specification.Sebastian Rasmussen
The function is used to read both SPcod and SPcoc, so all comments should refer to both marker segments' parameter names.
2019-09-03Merge pull request #1164 from sebras/masterEven Rouault
openjp2/j2k: Report error if all wanted components are not decoded.
2019-04-25Change opj_j2k_check_poc_val() to take into account tile numberEven Rouault
2019-04-25Fix POC in multi-tile scenarios: avoid almost endless loop when a tile has ↵Even Rouault
no POC settings
2019-04-25opj_j2k_check_poc_val(): prevent potential write outside of allocated arrayEven Rouault
2019-04-25opj_j2k_check_poc_val(): fix starting index for checking layer dimensionEven Rouault
The standard mandates that the layer index always starts at zero for every progression.
2019-04-25compression: emit POC marker when only one single POC is requested (fixes #1191)Even Rouault
2019-04-23j2k.c: use correct naming convention for total_data_size variableEven Rouault
2019-02-21openjp2/j2k: Report error if all wanted components are not decoded.Sebastian Rasmussen
Previously the caller had to check whether each component data had been decoded. This means duplicating the checking in every user of openjpeg which is unnecessary. If the caller wantes to decode all or a set of, or a specific component then openjpeg ought to error out if it was unable to do so. Fixes #1158.
2018-09-05openjp2/jp2: Fix two format stringsStefan Weil
Compiler warnings: src/lib/openjp2/jp2.c:1008:35: warning: too many arguments for format [-Wformat-extra-args] src/lib/openjp2/j2k.c:1928:73: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘OPJ_OFF_T {aka long int}’ [-Wformat=] Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-06-20Avoid assertion when running opj_j2k_merge_ppt() several time due to ↵Even Rouault
e6674f7ed66abdb32a0be5944f618722b6a7b5d5 revert. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2785
2018-06-20Revert "Avoid assertion in opj_j2k_merge_ppt() in case premature EOC is ↵Even Rouault
encountered in opj_j2k_read_tile_header(). Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2785. Credit to OSS Fuzz" (fixes #1120) This reverts commit 9906fbf737692486cebabe98169988d818e2e66a. which broke decoding of images where TNsot == 0
2017-11-30opj_j2k_read_cod: remove check for 'No more than one COD marker per tile' ↵Even Rouault
(fixes #1043) This check was added per https://github.com/uclouvain/openjpeg/commit/daed8cc9195555e101ab708a501af2dfe6d5e001 to fix https://github.com/uclouvain/openjpeg/issues/476 , but it does not seem to be necessary with latest master (issue476.jp2 doesn't cause memory issues), and breaks reading legit files.
2017-11-30Fix typo in commentsEven Rouault