summaryrefslogtreecommitdiff
path: root/src/lib/openjp2/j2k.c
AgeCommit message (Collapse)Author
2019-12-03Add some more errno to debug 'failed to start J2K encoding'Carl Hetherington
2019-12-03Add some error codes to debug failure in opj_j2k_start_compress.Carl Hetherington
2017-09-01opj_j2k_setup_encoder(): emit warnings if tcp_rates are not decreasing or ↵Even Rouault
tcp_distoratio are not increasing (#1009)
2017-09-01opj_j2k_setup_encoder(): avoid potential int overflow in computations ↵Even Rouault
related to max_cs_size
2017-09-01opj_compress help: revert 32572617765cb9d77302384653a48d793b8f657f and ↵Even Rouault
indicate 1 again as being the value to get lossless for -r. In opj_j2k_setup_encoder(), make sure that ll rates[] <= 1.0 are set to 0. Document 0 as being lossless for -q / tcp_distoratio (#1009)
2017-08-28Make opj_set_decode_area() and opj_decode() take into account ↵Even Rouault
opj_set_decoded_resolution_factor() (#1006, affect API use) * Better document usage of opj_set_decode_area(), ie expecting coordinates in full resolution/reference grid even if requesting at a lower resolution factor * Make sure that image->comps[].factor is set by opj_set_decode_area() and opj_decode() from the value specified in opj_set_decoded_resolution_factor() * opj_decompress: add 2 environmenet variables to test alternate ways of using the API, namely USE_OPJ_SET_DECODED_RESOLUTION_FACTOR=YES to use opj_set_decoded_resolution_factor() instead of parameters.cp_reduce, and SKIP_OPJ_SET_DECODE_AREA=YES to not call opj_set_decode_area() if -d is not specified.
2017-08-21j2k.c: fix comment, and remove FIXMEEven Rouault
2017-08-17opj_j2k_update_rates(): grow tile size buffer for some situationsEven Rouault
2017-08-17Sub-tile decoding: only decode precincts and codeblocks that intersect the ↵Even Rouault
window specified in opj_set_decode_area()
2017-08-16opj_t2_encode_packet(): fix potential write heap buffer overflow (#992)Even Rouault
2017-08-16opj_j2k_write_sot(): fix potential write heap buffer overflow (#991)Even Rouault
2017-08-15Fix assertion in debug mode / heap-based buffer overflow in ↵Even Rouault
opj_write_bytes_LE for Cinema profiles with numresolutions = 1 (#985)
2017-08-14Use const qualifier for j2k_prog_order_listStefan Weil
This allows more compiler optimizations. Signed-off-by: Stefan Weil <sw@weilnetz.de>
2017-08-10Propagate event manager down to opj_t2_encode_packet() and use it to emit an ↵Even Rouault
error message when the output buffer is too small
2017-08-10Fix crash on encoding if using opj_set_default_encoder_parameters() without ↵Even Rouault
defining tcp_numlayers
2017-08-09Remove useless opj_tcd_t::enumcs field added per #975Even Rouault
2017-08-09Partial revert BPC related check of #975 (#979)Even Rouault
PR #975 introduced a check that rejects images that have different bit depth/sign per compoment in SIZ marker if the JP2 IHDR box has BPC != 255 This didn't work properly if decoding a .j2k file since the new bit added in opj_cp_t wasn't initialized to the right value. For clarity, tThis new bit has also been renamed to allow_different_bit_depth_sign But looking closer at the code, it seems we were already tolerant to inconsistencies. For example we parsed a JP2 BPCC box even if BPC != 255 (just a warning is emitted) So failing hard in opj_j2k_read_siz() wouldn't be very inconsistent, and that alone cannot protect against other issues, so just emit a warning if BPC != 255 and the SIZ marker contains different bit depth/sign per component. Note: we could also check that the content of JP2 BPCC box is consistant with the one of the SIZ marker.
2017-08-08Merge pull request #975 from szukw000/changes-for-afl-testsAntonin Descampe
Catch images broken by AFL
2017-08-07Decoding: do not allocate memory for the codestream of each codeblockEven Rouault
Currently we allocate at least 8192 bytes for each codeblock, and copy the relevant parts of the codestream in that per-codeblock buffer as we decode packets. As the whole codestream for the tile is ingested in memory and alive during the decoding, we can directly point to it instead of copying. But to do that, we need an intermediate concept, a 'chunk' of code-stream segment, given that segments may be made of data at different places in the code-stream when quality layers are used. With that change, the decoding of MAPA_005.jp2 goes down from the previous improvement of 2.7 GB down to 1.9 GB. New profile: n4: 1885648469 (heap allocation functions) malloc/new/new[], --alloc-fns, etc. n1: 1610689344 0x4E78287: opj_aligned_malloc (opj_malloc.c:61) n1: 1610689344 0x4E71D7B: opj_alloc_tile_component_data (tcd.c:676) n1: 1610689344 0x4E7272C: opj_tcd_init_decode_tile (tcd.c:816) n1: 1610689344 0x4E4BDD9: opj_j2k_read_tile_header (j2k.c:8618) n1: 1610689344 0x4E4C8A2: opj_j2k_decode_tiles (j2k.c:10349) n1: 1610689344 0x4E4E36E: opj_j2k_decode (j2k.c:7847) n1: 1610689344 0x4E52FA2: opj_jp2_decode (jp2.c:1564) n0: 1610689344 0x40374E: main (opj_decompress.c:1459) n1: 219232541 0x4E4BBF0: opj_j2k_read_tile_header (j2k.c:4685) n1: 219232541 0x4E4C8A2: opj_j2k_decode_tiles (j2k.c:10349) n1: 219232541 0x4E4E36E: opj_j2k_decode (j2k.c:7847) n1: 219232541 0x4E52FA2: opj_jp2_decode (jp2.c:1564) n0: 219232541 0x40374E: main (opj_decompress.c:1459) n1: 39822000 0x4E727A9: opj_tcd_init_decode_tile (tcd.c:1219) n1: 39822000 0x4E4BDD9: opj_j2k_read_tile_header (j2k.c:8618) n1: 39822000 0x4E4C8A2: opj_j2k_decode_tiles (j2k.c:10349) n1: 39822000 0x4E4E36E: opj_j2k_decode (j2k.c:7847) n1: 39822000 0x4E52FA2: opj_jp2_decode (jp2.c:1564) n0: 39822000 0x40374E: main (opj_decompress.c:1459) n0: 15904584 in 52 places, all below massif's threshold (1.00%)
2017-08-07Add opj_image_data_alloc() / opj_image_data_free()Even Rouault
As bin/common/color.c used to directly call malloc()/free(), we need to export functions dedicated to allocating/freeing image component data.
2017-08-07Fix crash on Windows due to b7594c0fcb9dd3aa6356d72c4a525d76168da689Even Rouault
b7594c0fcb9dd3aa6356d72c4a525d76168da689 may put opj_tcd_tilecomp_t->data allocated by opj_alloc_tile_component_data() as the image->comps[].data. As opj_alloc_tile_component_data() use opj_aligned_malloc() we must be sure to ue opj_alined_malloc()/_free() in all places where we alloc/free image->comps[].data. Note: this might have some compatibility impact in case user code does itself the allocation/free of image->comps[].data
2017-08-07Decrease memory consumption for whole image single tile decoding.Even Rouault
We can use the same buffer for the tile decoding and the final image, and save the intermediate buffer to transfer between those. Effect on the decoding of MAPA (9944 x 13498 x 3 components of size byte) Peak memory from 4.5 GB to 2.7 GB Now: n5: 2699708767 (heap allocation functions) malloc/new/new[], --alloc-fns, etc. n1: 1610689344 0x4E77E07: opj_aligned_malloc (opj_malloc.c:61) <-- final image n1: 1610689344 0x4E7195B: opj_alloc_tile_component_data (tcd.c:676) n1: 1610689344 0x4E722D2: opj_tcd_init_decode_tile (tcd.c:816) n1: 1610689344 0x4E4BCF1: opj_j2k_read_tile_header (j2k.c:8597) n1: 1610689344 0x4E4C742: opj_j2k_decode_tiles (j2k.c:10324) n1: 1610689344 0x4E4E20E: opj_j2k_decode (j2k.c:7826) n1: 1610689344 0x4E52E42: opj_jp2_decode (jp2.c:1564) n0: 1610689344 0x40369E: main (opj_decompress.c:1459) n1: 815554560 0x4E72231: opj_tcd_init_decode_tile (tcd.c:1217) <-- working memory for code blocks: 9944*13498/64/64*8192*3 n1: 815554560 0x4E4BCF1: opj_j2k_read_tile_header (j2k.c:8597) n1: 815554560 0x4E4C742: opj_j2k_decode_tiles (j2k.c:10324) n1: 815554560 0x4E4E20E: opj_j2k_decode (j2k.c:7826) n1: 815554560 0x4E52E42: opj_jp2_decode (jp2.c:1564) n0: 815554560 0x40369E: main (opj_decompress.c:1459) n1: 219758391 0x4E4C0BF: opj_j2k_read_tile_header (j2k.c:4661) <-- ingestion of code stream n1: 219758391 0x4E4C742: opj_j2k_decode_tiles (j2k.c:10324) n1: 219758391 0x4E4E20E: opj_j2k_decode (j2k.c:7826) n1: 219758391 0x4E52E42: opj_jp2_decode (jp2.c:1564) n0: 219758391 0x40369E: main (opj_decompress.c:1459) n1: 39822000 0x4E7224F: opj_tcd_init_decode_tile (tcd.c:1224) <-- OPJ_J2K_DEFAULT_NB_SEGS*sizeof(opj_tcd_seg_t) per codeblock n1: 39822000 0x4E4BCF1: opj_j2k_read_tile_header (j2k.c:8597) n1: 39822000 0x4E4C742: opj_j2k_decode_tiles (j2k.c:10324) n1: 39822000 0x4E4E20E: opj_j2k_decode (j2k.c:7826) n1: 39822000 0x4E52E42: opj_jp2_decode (jp2.c:1564) n0: 39822000 0x40369E: main (opj_decompress.c:1459) n0: 13884472 in 49 places, all below massif's threshold (1.00%) Before: n5: 4493329848 (heap allocation functions) malloc/new/new[], --alloc-fns, etc. n2: 1610709160 0x4E77C87: opj_aligned_malloc (opj_malloc.c:61) n1: 1610689344 0x4E717DB: opj_alloc_tile_component_data (tcd.c:676) n1: 1610689344 0x4E72152: opj_tcd_init_decode_tile (tcd.c:816) n1: 1610689344 0x4E4BCF1: opj_j2k_read_tile_header (j2k.c:8597) n1: 1610689344 0x4E4C64A: opj_j2k_decode_tiles (j2k.c:10318) n1: 1610689344 0x4E4E08E: opj_j2k_decode (j2k.c:7826) n1: 1610689344 0x4E52CC2: opj_jp2_decode (jp2.c:1564) n0: 1610689344 0x40369E: main (opj_decompress.c:1459) n0: 19816 in 2 places, all below massif's threshold (1.00%) n1: 1610689344 0x4E43F36: opj_j2k_update_image_data.isra.7 (j2k.c:8743) n1: 1610689344 0x4E4C5C1: opj_j2k_decode_tiles (j2k.c:10358) n1: 1610689344 0x4E4E08E: opj_j2k_decode (j2k.c:7826) n1: 1610689344 0x4E52CC2: opj_jp2_decode (jp2.c:1564) n0: 1610689344 0x40369E: main (opj_decompress.c:1459) n1: 815554560 0x4E720B1: opj_tcd_init_decode_tile (tcd.c:1217) n1: 815554560 0x4E4BCF1: opj_j2k_read_tile_header (j2k.c:8597) n1: 815554560 0x4E4C64A: opj_j2k_decode_tiles (j2k.c:10318) n1: 815554560 0x4E4E08E: opj_j2k_decode (j2k.c:7826) n1: 815554560 0x4E52CC2: opj_jp2_decode (jp2.c:1564) n0: 815554560 0x40369E: main (opj_decompress.c:1459) n1: 402672336 0x4E4C545: opj_j2k_decode_tiles (j2k.c:10336) n1: 402672336 0x4E4E08E: opj_j2k_decode (j2k.c:7826) n1: 402672336 0x4E52CC2: opj_jp2_decode (jp2.c:1564) n0: 402672336 0x40369E: main (opj_decompress.c:1459) n0: 53704448 in 58 places, all below massif's threshold (1.00%)
2017-08-04opj_j2k_read_sot(): check current TPSot number regarding previous (non-zero) ↵Even Rouault
TNsot to avoid opj_j2k_merge_ppt() to be called several times. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2851. Credit to OSS Fuzz
2017-08-02First change on changes-for-afl-testsszukw000
2017-07-31Catch images broken by AFLszukw000
2017-07-30Fix breakage of 22bf99ce0220811bfce1562ee61423cb0245b683Even Rouault
2017-07-30Test return value of opj_j2k_setup_decoding_tile() (commit ↵Even Rouault
https://github.com/uclouvain/openjpeg/pull/561/commits/ec31fa0c7f1ff8979312c07296cba41584c458a0 by ak-dxdy, #561)
2017-07-30j2k.c: remove hardcoded constants related to m_state, and useless FIXMEEven Rouault
2017-07-30opj_j2k_set_decode_area: replace assertions by runtime checks. Fixes ↵Even Rouault
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2795. Credit to OSS Fuzz
2017-07-29opj_tcd_get_decoded_tile_size(): fix potential UINT32 overflow (#854, ↵Even Rouault
CVE-2016-5152) Fix derived from https://pdfium.googlesource.com/pdfium.git/+/d8cc503575463ff3d81b22dad292665f2c88911e/third_party/libopenjpeg20/0018-tcd_get_decoded_tile_size.patch
2017-07-29Avoid assertion in opj_j2k_merge_ppt() in case premature EOC is encountered ↵Even Rouault
in opj_j2k_read_tile_header(). Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2785. Credit to OSS Fuzz
2017-07-28Fix null pointer dereference in opj_j2k_add_mct() (#895)Even Rouault
Fixes openjeg-crashes-2017-07-27/issue879-poc1.j2k of #895
2017-07-28Avoid use-after-free when a MCT marker is found after a MCC one (#895)Even Rouault
Fixes openjeg-crashes-2017-07-27/issue880-poc2.j2k of #895
2017-07-27Avoid undefined shift behaviour if bit depth == 32 (#895)Even Rouault
Fixes openjeg-crashes-2017-07-27/id:000000,sig:11,src:003798,op:ext_AO,pos:128.jp2
2017-07-27opj_j2k_update_image_data / opj_tcd_update_tile_data: fix unaligned ↵Even Rouault
load/store (#895) When components don't have the same width, unaligned load/store are possible. Fixes openjeg-crashes-2017-07-27/id:000000,sig:11,src:001342,op:flip4,pos:162.jp2 of #895
2017-07-27Avoids undefined shift behaviour in m_dc_level_shift computationEven Rouault
Fixes warning found on clusterfuzz-testcase-minimized-5146316340461568 https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2495 Credit to OSS Fuzz
2017-07-26Fix assertion / memory leak in opj_j2k_merge_ppt() on corrupted images (#939)Even Rouault
Fixes issue on id:000020,sig:06,src:001958,op:flip4,pos:149 that has two SOT markers for the same tile with the same tile part number, causing opj_j2k_merge_ppt() to be called several times.
2017-07-03opj_j2k_read_header_procedure(): validate marker size to avoid excessive ↵Even Rouault
memory allocation attempt
2017-05-23CMake: add stronger warnings for openjp2 lib/bin by default, and error out ↵Even Rouault
on declaration-after-statement And remove occurences of unused arguments in src/lib/openjp2
2017-05-09Reformat whole codebase with astyle.options (#128)Even Rouault
2016-09-14Fix some warnings (#838)Matthieu Darbois
Fix warnings introduced by uclouvain/openjpeg#786
2016-09-08Merge branch 'master' of https://github.com/uclouvain/openjpeg into ↵Even Rouault
tier1_optimizations_multithreading_2 Conflicts: src/lib/openjp2/t1.c
2016-09-06fix incrementing of "l_tcp->m_nb_mcc_records" in opj_j2k_read_mcc (#820)Matthieu Darbois
2016-09-06Add overflow check in opj_j2k_update_image_data (#817)Matthieu Darbois
2016-05-25Add opj_codec_set_threads() in public API and propagate resulting thread ↵Even Rouault
pool to tcd level By default, only the main thread is used. If opj_codec_set_threads() is not used, but the OPJ_NUM_THREADS environment variable is set, its value will be used to initialize the number of threads. The value can be either an integer number, or "ALL_CPUS". If OPJ_NUM_THREADS is set and this function is called, this function will override the behaviour of the environment variable.
2016-05-08Fix Out-of-Bounds Access in function opj_tgt_resetmayeut
Fix uclouvain/openjpeg#775
2016-04-30Fix some coverity warningsmayeut
2016-04-30Fix warnings (#763)Matthieu Darbois
2016-04-29cppcheck fix for openjp2 (#740)julienmalik
2016-04-28Check SSIZ is valid in opj_j2k_read_siz (#762)Matthieu Darbois