Commit Graph

337 Commits

Author SHA1 Message Date
Andreas Rheinhardt 1ea3650823 Replace all occurences of av_mallocz_array() by av_calloc()
They do the same.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-20 01:03:52 +02:00
Michael Niedermayer 3c659f8618 avcodec/jpeg2000dec: Check that atom header is within bytsetream
Fixes: Infinite loop
Fixes: 36666/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5912760671141888

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-09-05 22:22:27 +02:00
Andreas Rheinhardt 3c26773ae2 avcodec/jpeg2000dec: Make decoder init-threadsafe
The JPEG-2000 decoder and encoder share common luts; the decoder
initializes them once, guarded by a dedicated AVOnce, whereas
the encoder initializes them always during init. This means that
the decoder is not init-threadsafe; in fact there is a potential
data race because these luts can be initialized while an active
decoder/encoder is using them.

Fix this and make the decoder init-threadsafe by making the
initialization function guard initialization itself with a dedicated
AVOnce.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-05-12 06:00:14 +02:00
Andreas Rheinhardt b43e946b71 avcodec/mqc: Hardcode tables to save space
mqc currently initializes three arrays at runtime; each of them
has 2 * 47 elements, one is uint16_t, two are uint8_t, so that their
combined size is 8 * 47. The source data for these initializations
is contained in an array of 47 elements of size six. Said array is
only used in order to initialize the other arrays, so the savings
are just 2 * 47B. Yet this is dwarfed by the size of the code for
performing the initializations: It is 109B (GCC 10.2, x64, -O3 albeit
in an av_cold function); this does not even include the size of the
code in the callers. So just hardcode these tables.

This also fixes a data race, because the encoder always initialized
these tables during init, although they might already be used at the
same time by already running encoder/decoder instances.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-05-12 06:00:14 +02:00
Andreas Rheinhardt a247ac640d avcodec: Constify AVCodecs
Given that the AVCodec.next pointer has now been removed, most of the
AVCodecs are not modified at all any more and can therefore be made
const (as this patch does); the only exceptions are the very few codecs
for external libraries that have a init_static_data callback.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:15 -03:00
Michael Niedermayer 2a2082a41b avcodec/jpeg2000dec: Check atom_size in jp2_find_codestream()
Fixes: Infinite loop
Fixes: 29722/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6412228041506816

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-02-10 12:28:30 +01:00
Michael Niedermayer a5ac81952e avcodec/jpeg2000dec: Check remaining data in packed_headers_stream before use
Fixes: out of array read
Fixes: 24487/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5165847820369920
Fixes: 24636/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5700973918683136
Fixes: 24683/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6202883897556992

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-10 14:54:32 +02:00
Michael Niedermayer 5036d7b20c avcodec/jpeg2000dec: Handle reducedresno of 32
Fixes: shift exponent 32 is too large for 32-bit type 'int'
Fixes: 24566/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6033783737024512

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Gautam Ramakrishnan <gautamramk@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-06 00:38:09 +02:00
Gautam Ramakrishnan a45935fe05 libavcodec/jpeg2000dec: Support for PPM marker
This patch adds support for PPM marker for JPEG2000
decoder. It allows the samples p1_03.j2k and p1_05.j2k
to be decoded.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-28 21:57:50 +02:00
Michael Niedermayer 6ea8f03bf4 avcodec/jpeg2000dec: Move reslevelno check before use in case JPEG2000_PGOD_RPCL
Fixes: division by zero
Fixes: 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
Fixes: 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Gautam Ramakrishnan <gautamramk@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-28 21:57:50 +02:00
Gautam Ramakrishnan ff5b9ece42 libavcodec/jpeg2000dec: Fix codeblock decode check
The codeblock decoder checks whether the mqc decoder
has decoded the right number of bytes. However, this
check does not account for the fact that the mqc encoder's
flush routine adds 2 bytes of data which does not have to be
read by the decoder. The check is modified to account for
this. This patch solves issue #4827

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-24 22:34:15 +02:00
Gautam Ramakrishnan b61d3dfab0 libavcodec/jpeg2000dec: Add check when done with main header markers
This patch sets a flag when the processing of the
main header is complete.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-23 16:30:02 +02:00
Gautam Ramakrishnan e39490615f libavcodec/jpeg2000dec: Support for Parameterless Markers
The JPEG2000 standard reserves marker values 0xFF30
to 0xFF3F to be used as parameterless markers. This
patch adds support to decode codestream with such
markers. This allows decoding of p0_02.j2k.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-19 10:59:43 +02:00
Gautam Ramakrishnan db7dfb4a79 libavcodec/jpeg2000 Fix RPCL Progression order check
The RPCL progression order check was incomplete. This
patch completes the check. Tested on p1_07.j2k.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-16 17:44:53 +02:00
Gautam Ramakrishnan 660386813d libavcodec/jpeg2000 Fix PCRL Progression Order check
The PCRL progression checks were incomplete. This patch
modifes completes the check. Tested on p1_05.j2k.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-16 10:13:22 +02:00
Gautam Ramakrishnan 05f3d37dd5 libavcodec/jpeg2000dec : Prevent overriding SOP marker bit
Currently, the COC marker overrides the SOP marker bit.
However, only the COD marker may set this value. This
patch fixes this bug.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-14 22:05:02 +02:00
Gautam Ramakrishnan 2c21955f52 libavcodec/jpeg2000dec.c: Enable image offsets
This patch enables support for image offsets.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-06 00:32:16 +02:00
Gautam Ramakrishnan 69522e0400 libavcodec/jpeg2000dec: Enhance pix fmt selection
This patch assigns default pix format values when
a match does not take place.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-06 00:32:16 +02:00
Gautam Ramakrishnan 579ac96a04 libavcodec/jpeg2000.c: Precinct size check removed
This patch removes a check which throws an error if
the log2 precinct width/height is 0. The standard allows
the first component to have 0 as the log2 width/height.
However, to ensure proper intialization of coding style,
an extra check has been added.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-06-30 20:35:23 +02:00
Gautam Ramakrishnan 42fdf402a7 libavcodec/jpeg2000dec.c Fixed WRITE_FRAME and tile co-ordinates:
libopenjpeg2000 uses ceiling division while dividing tile
co-ordinates with the sample separation. Also, corrections
were made to the WRITE_FRAME macro.

Improves: p1_01.j2k and p1_07.j2k

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-06-27 12:44:09 +02:00
Gautam Ramakrishnan 2760de16bc libavcodec/jpeg2000dec.c: Modify image dimensions
Reduce image size of the image if all components have
a non zero sample separation. This is to replicate the
output of opj_decompress.

Improves: p1_01.j2k

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-06-27 12:43:51 +02:00
Michael Niedermayer c579ceffbe avcodec/jpeg2000dec: Fix/check for multiple integer overflows
Fixes: shift exponent 35 is too large for 32-bit type 'int'
Fixes: 22857/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5202709358837760

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-06-14 19:17:07 +02:00
Michael Niedermayer 4b2248594c avcodec/jpeg2000dec: clear pointer which become stale in get_ppt()
Fixes: use after free
Fixes: 22484/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5671488765296640

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Gautam Ramakrishnan <gautamramk@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-06-01 23:32:28 +02:00
Michael Niedermayer ea29f07b2f avcodec/jpeg2000dec: Free packed_headers
Fixes: memleak
Fixes: 21784/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-565256551058636

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Gautam Ramakrishnan <gautamramk@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-05-17 00:36:20 +02:00
Gautam Ramakrishnan e58766ba12 libavcodec/jpeg2000dec.c: ROI marker support
This patch adds support for decoding images
with a Region of Interest. Allows decoding
samples such as p0_03.j2k. This patch should
fix ticket #4681.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-04-23 19:30:07 +02:00
Gautam Ramakrishnan 6bd4a26168 libavcodec/jpeg2000dec.c: Support for CRG marker
This patch adds support to skip the CRG marker.
The CRG marker, is an informational marker.
Allows samples such as p0_03.j2k to be decoded.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-04-22 22:57:38 +02:00
Carl Eugen Hoyos d727fea4da lavc/jpeg2000dec: Cosmetics, re-indent after last commit. 2020-04-15 20:03:33 +02:00
Carl Eugen Hoyos cbe3f1b1fb lavc/jpeg2000dec: Allow to force a compatible pix_fmt.
This copies the behaviour of the libopenjpeg decoder.
Fixes ticket #5919.
2020-04-15 20:00:51 +02:00
Gautam Ramakrishnan e8344f21e1 libavcodec/jpeg2000dec.c: fix error in cod marker
This patch fixes an error where the COC marker
overrides all data of the SPcod field of the
COD marker. It must override only one bit of
SPcod field. This now allows p0_08.j2k to be
decoded correctly (mentioned in #4679).

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-04-11 18:15:58 +02:00
Andreas Rheinhardt 7104c4dd88 avcodec/jpeg2000dec: Fix mixed declaration and code
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-09 18:19:04 +02:00
Gautam Ramakrishnan e531891f3d libavcodec/jpeg2000dec.c: Add support for PPT marker
This patch adds functional changes to support the
PPT marker. This patch fixes bug ticket #4610.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-04-09 13:43:15 +02:00
Gautam Ramakrishnan 88f95253e1 libavcodec/jpeg2000dec.c: Fix indentation
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-04-04 18:04:21 +02:00
Gautam Ramakrishnan e116cb45c2 libavcodec/jpeg2000dec.c: Handle non EOC streams
This patch allows decoding of j2k streams which do
not have an EOC marker.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-04-04 18:04:21 +02:00
Gautam Ramakrishnan 26a36801c0 avcodec/jpeg2000dec: error check when processing tlm marker
Validate the value of ST field in the TLM marker of JPEG2000.
Throw an error when ST takes value of 0b11.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-03-27 21:36:06 +01:00
Michael Niedermayer 2be0bd12b7 avcodec/jpeg2000dec: Fix return type of get_plt()
Found-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-04-25 19:18:29 +02:00
Michael Niedermayer e627113329 avcodec/jpeg2000dec: Check PLT data somewhat
Fixes: Timeout (21sec -> 0.6sec)
Fixes: 14134/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5768371078955008

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-04-25 14:49:51 +02:00
Michael Niedermayer 6381b6f6a9 avcodec/jpeg2000dec: Replace the step_x/y assert by a check in the CPRL case as with the PCRL case
Fixes: assertion failure
Fixes: 14246/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5758393601490944

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-04-25 14:49:51 +02:00
Michael Niedermayer b8f53a2342 avcodec/jpeg2000dec: Skip de-quantization of empty areas
Fixes: Timeout (26sec -> 18sec)
Fixes: 13448/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-576903098243481

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-03-25 13:20:30 +01:00
Michael Niedermayer fe0416f8a1 avcodec/jpeg2000dec: Skip DWT if nothing is coded
Improves speed in uncommon case

Fixes: Timeout
Fixes: 10964/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5132066034286592

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-08 17:01:03 +01:00
Michael Niedermayer 305e523105 avcodec/jpeg2000dec: Fix off by 1 error in JPEG2000_PGOD_CPRL handling
Fixes: assertion failure
Fixes: 10785/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5672160496975872

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-10-23 00:51:55 +02:00
Michael Niedermayer 652d7c6348 avcodec/jpeg2000dec: Fixes invalid shifts in jpeg2000_decode_packets_po_iteration()
Fixes: shift exponent 47 is too large for 32-bit type 'int'
Fixes: 9163/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5661750182543360

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-04 01:10:28 +02:00
Michael Niedermayer 0898a3d990 avcodec/jpeg2000dec: Check that there are enough bytes for all tiles
Fixes: OOM
Fixes: 8781/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5810709081358336

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-04 01:10:28 +02:00
Carl Eugen Hoyos 1083808c48 lavc/jpeg2000dec: Move a variable declaration closer to its usage. 2018-05-22 12:55:46 +02:00
Carl Eugen Hoyos 848ce6f0a6 lavc/jpeg2000dec: Use a define to clarify the meaning of a constant. 2018-05-22 12:54:32 +02:00
Michael Niedermayer 652ba72ed3 avcodec/jpeg2000dec: Fix undefined shift in the jpeg2000_decode_packets_po_iteration() CPRL case
Fixes: shift exponent 47 is too large for 32-bit type 'int'
Fixes: 7955/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6016721977606144

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-05-06 21:02:04 +02:00
Michael Niedermayer a96c131eb5 avcodec/jpeg2000dec: Skip init for component in CPRL if nothing is to be done
Fixes: assertion failure
Fixes: 7949/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-4819602782552064

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-05-06 21:02:04 +02:00
Michael Niedermayer 3543522d20 avcodec/jpeg2000dec: Reduce the number of tile parts allocated
This is large enough for all jpeg2000 files i tested. If some need more then this
should be changed to dynamic allocation. Dynamic allocation would need to be done
carefully as these are many relatively small arrays so repeatly reallocating them
would not be good.
The decrease is a clean and simple solution assuming it works for all files.

Fixes: OOM
Fixes: 6534/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-4821490731057152

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-05-06 21:02:04 +02:00
Michael Niedermayer 01370b31ac avcodec/jpeg2000dec: Use av_image_check_size2()
Fixes: OOM
Fixes: 5733/clusterfuzz-testcase-minimized-4906757966004224

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-02-17 20:31:39 +01:00
Muhammad Faiz 3caecf7ce8 avcodec: do not use init_static_data on some codecs
They don't modify AVCodec, no needs to call it at register. They will be
wasteful if these codecs are unused. Instead, call static data initialization
at codecs' init.

Benchmark:
old: 51281340 decicycles in avcodec_register_all,       1 runs,      0 skips
new:  6738960 decicycles in avcodec_register_all,       1 runs,      0 skips

Reviewed-by: wm4 <nfxjfg@googlemail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
2018-02-04 06:11:07 +07:00
Carl Eugen Hoyos 658bdc6771 lavc/jpeg2000dec: Support reading 64-bit atom size.
Fixes ticket #6935.
2017-12-28 02:58:56 +01:00