Commit Graph

51 Commits

Author SHA1 Message Date
Even Rouault 8f5aff1dff
pi.c: avoid out of bounds access with POC (fixes #1302) 2020-12-04 20:45:25 +01:00
Even Rouault 00383e162a
pi.c: avoid out of bounds access with POC (refs https://github.com/uclouvain/openjpeg/issues/1293#issuecomment-737122836) 2020-12-02 14:03:11 +01:00
Even Rouault 4edb8c8337
Add support for generation of PLT markers in encoder
* -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-21 15:55:44 +02:00
Even Rouault 271a71ef0f
Fix warnings about signed/unsigned casts in pi.c 2020-04-16 23:34:10 +02:00
Even Rouault 84f3bebbff
Implement writing of IMF profiles
Add -IMF switch to opj_compress as well
2020-02-12 15:55:25 +01:00
Even Rouault 4cb1f66304
pi.c: avoid integer overflow, resulting in later invalid access to memory in opj_t2_decode_packets(). Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18979 2019-11-17 01:18:26 +01:00
Young_X c58df14990 [OPENJP2] change the way to compute *p_tx0, *p_tx1, *p_ty0, *p_ty1 in function
opj_get_encoding_parameters

Signed-off-by: Young_X <YangX92@hotmail.com>
2018-11-28 14:39:14 +08:00
Even Rouault 51eb86d8f7 Fix warnings in pi.c raised by VS11 analyze (#190) 2017-07-29 19:43:23 +02:00
Even Rouault 11445eddad opj_pi_update_decode_poc(): limit layno1 to the number of layers (CVE-2016-1626 and CVE-2016-1628, #850)
This has been recently fixed in a less elegant way per
80818c39f5
2017-07-29 19:03:13 +02:00
Even Rouault 71b4f5b124 opj_pi_next_pcrl(): avoid undefined shift behaviour. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2787. Credit to OSS Fuzz 2017-07-29 15:52:11 +02:00
Even Rouault 6c4e5bacb9 opj_pi_next_rpcl / opj_pi_next_pcrl / opj_pi_next_cprl: avoid int overflow (#895)
Fixes int overflow on openjeg-crashes-2017-07-27/id:000000,sig:08,src:000879,op:flip2,pos:128.jp2
2017-07-27 19:22:14 +02:00
Even Rouault a88cbb6a0b Fix various undefined shift behaviour in pi.c
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2496
Credit to OSS Fuzz
2017-07-26 22:53:59 +02:00
Even Rouault 5c5319984b Avoid division by zero in opj_pi_next_rpcl, opj_pi_next_pcrl, opj_pi_next_cprl (#938)
Fixes crash on id_000004,sig_06,src_000679,op_arith8,pos_49,val_-17
2017-07-26 18:05:56 +02:00
Even Rouault 80818c39f5 Avoid index out of bounds access to pi->include[] (#938)
Fix id:000098,sig:11,src:005411,op:havoc,rep:2 test case
2017-07-26 12:50:51 +02:00
Even Rouault d27ccf01c6 Avoid division by zero in opj_pi_next_rpcl, opj_pi_next_pcrl and opj_pi_next_cprl (#938)
Fixes issues with id:000026,sig:08,src:002419,op:int32,pos:60,val:+32 and
id:000019,sig:08,src:001098,op:flip1,pos:49
2017-07-26 11:32:41 +02:00
Even Rouault 563bd8499e Reformat whole codebase with astyle.options (#128) 2017-05-09 20:46:20 +02:00
Matthieu Darbois 9a07ccb3d0 Add overflow checks for opj_aligned_malloc (#841)
See
https://pdfium.googlesource.com/pdfium/+/b20ab6c7acb3be1393461eb650ca8fa4660c937e/third_party/libopenjpeg20/0020-opj_aligned_malloc.patch
2016-09-15 01:57:53 +02:00
Matthieu Darbois ef01f18dfc Cast to size_t before multiplication
Need to cast to size_t before multiplication otherwise overflow check is useless.
2016-09-08 07:34:46 +02:00
trylab c16bc057ba Fix an integer overflow issue (#809)
Prevent an integer overflow issue in function opj_pi_create_decode of
pi.c.
2016-09-06 07:55:49 +02:00
Matthieu Darbois 29313eb5f1 Fix unsigned int overflow reported by UBSan (#761)
* Fix unsigned int overflow reported by UBSan

Please add -DOPJ_UBSAN_BUILD to CFLAGS when building with
-fsanitize=undefined,unsigned-integer-overflow

It seems clang/gcc do not allow to disable checking for block of code
other than function or file.
2016-04-28 13:16:43 +02:00
Stefan Weil 99c4f621bd Fix duplicate article in comments
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2016-01-06 08:55:29 +01:00
mayeut c423cc84e7 Remove some warnings when building
Update #442
2015-07-26 02:41:39 +02:00
mayeut ae4799ad07 Add some missing static
Still needs to check j2k.c & jp2.c
Update uclouvain/openjpeg#243
2015-07-18 02:39:32 +02:00
Antonin Descampe 2d24b6000d [trunk] added overflow checks (fixes issue 431)
Thanks mdarbois
2015-02-02 16:11:31 +00:00
Antonin Descampe 5d00b719f4 [trunk] fixed a buffer overflow in opj_tcd_init_decode_tile
Update issue 431
2015-01-15 18:16:29 +00:00
Antonin Descampe a1c754c737 [trunk] fixed warning from r2891 2014-10-01 12:11:43 +00:00
Antonin Descampe fef1276901 [trunk] fixed bad use of case statement (fixes issue 381) 2014-09-30 12:19:13 +00:00
Antonin Descampe 50a205d20f [trunk] improve memory management (fixes issue 359) 2014-09-16 15:48:04 +00:00
Antonin Descampe 7199d9b5d3 [trunk] refactoring of rsiz, profiles, and extensions management 2014-04-17 09:31:37 +00:00
Antonin Descampe d19a4ab676 [trunk] updated copyright and added copyright notice required by ISO, in each file; updated AUTHORS, NEWS 2014-04-03 15:30:57 +00:00
Mathieu Malaterre 237253d83b [trunk] Add some documention in the pi code 2014-03-13 10:42:06 +00:00
Mathieu Malaterre e4d077bc98 [trunk] Another round of fixes for sign conversion warnings.
Update issue 256
2014-03-07 11:06:13 +00:00
Mickael Savinaud ec0fe09138 [trunk] move opj_bool to OPJ_BOOL to follow the other type 2012-11-15 13:13:36 +00:00
Mickael Savinaud 21b0ccf859 [trunk] rename public symbols with OPJ_ prefix (enum part) 2012-11-15 12:58:32 +00:00
Mickael Savinaud 84c93c2fea [trunk] rename public symbols with OPJ_ prefix 2012-11-15 12:25:11 +00:00
Mickael Savinaud e3c2305ff4 [trunk] remove warnings raised by flags -Wall -Wextra -pedantic 2012-11-13 17:35:15 +00:00
Mickael Savinaud 7307bb6e9a [trunk] remove warnings raised by flags -Wall -Wextra -pedantic and vs9 analyzer 2012-11-13 15:16:35 +00:00
Mathieu Malaterre 759be64115 [trunk] Fix remainings issues with doxygen doc
Convert DOS files to UNIX eol
2012-10-29 14:35:11 +00:00
Mickael Savinaud 18e7fcc37f [trunk] remove warnings related to the use of -Wall -Wextra -pedantic 2012-10-29 10:08:35 +00:00
Mickael Savinaud 9b6900b058 [trunk] [trunk] remove old opj_tcp and rename opj_tcp_v2 to opj_tcp 2012-10-25 15:15:02 +00:00
Mickael Savinaud 7f7ef068fc [trunk] [trunk] remove old opj_cp and rename opj_cp_v2 to opj_cp 2012-10-25 15:09:31 +00:00
Mathieu Malaterre 44a5108e1d [trunk] Add missing newline character 2012-10-15 07:57:19 +00:00
Mickael Savinaud 4b140e060b [trunk] rename int.h to opj_intmath.h and rename all its functions with opj_ prefix 2012-10-05 09:10:15 +00:00
Mickael Savinaud e798fe37e1 [trunk]remove warnings in pi.c through the update of poc struct types with new opj_types. 2012-10-03 17:03:41 +00:00
Mickael Savinaud 2d52e409c2 [trunk] (style) move global pi functions to the right place and update indentation 2012-10-03 14:41:40 +00:00
Mickael Savinaud 1b5e677d0c [trunk] remove old v1 functions and rename pi_initialise_encode_v2 to opj_pi_initialise_encode; pi_create_encode_v2 to opj_pi_create_decode; pi_destroy_v2 to opj_pi_destroy; pi_create_decode_v2 to opj_pi_create_decode 2012-10-03 14:29:26 +00:00
Mickael Savinaud c508923f04 [trunk] update pi_check_next_level with the opj_ prefix and change output type to be more convenient 2012-10-03 13:25:03 +00:00
Mickael Savinaud 6c4024796e [trunk]rename pi_update_encoding_parameters to opj_pi_update_encoding_parameters 2012-10-03 12:50:44 +00:00
Mickael Savinaud bd2c6cfa55 [trunk] replace pi_next by opj_pi_next 2012-10-03 12:43:15 +00:00
Mickael Savinaud bd74db932e [trunk] update local function of pi.c with the opj_ prefix and the new opj types 2012-10-03 12:39:17 +00:00