summaryrefslogtreecommitdiff
path: root/libavcodec/mjpegdec.c
Commit message (Collapse)AuthorAge
* avcodec: Constify AVCodecsAndreas Rheinhardt2021-04-27
| | | | | | | | | | 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>
* avcodec/mjpegdec: postpone calling ff_get_buffer() until the SOS markerJames Almer2021-04-25
| | | | | | | | | | | | | | | With JPEG-LS PAL8 samples, the JPEG-LS extension parameters signaled with the LSE marker show up after SOF but before SOS. For those, the pixel format chosen by get_format() in SOF is GRAY8, and then replaced by PAL8 in LSE. This has not been an issue given both pixel formats allocate the second data plane for the palette, but after the upcoming soname bump, GRAY8 will no longer do that. This will result in segfauls when ff_jpegls_decode_lse() attempts to write the palette on a buffer originally allocated as a GRAY8 one. Work around this by calling ff_get_buffer() after the actual pixel format is known. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/jpeglsdec: Don't presume the context to contain a JLSStateAndreas Rheinhardt2021-04-20
| | | | | | | | | | | | | | | Before 9b3c46a081a9f01559082bf7a154fc6be1e06c18 every call to ff_jpegls_decode_picture() allocated and freed a JLSState. This commit instead put said structure into the context of the JPEG-LS decoder to avoid said allocation. But said function can also be called from other MJPEG-based decoders and their contexts doesn't contain said structure, leading to segfaults. This commit fixes this: The JLSState is now allocated on the first call to ff_jpegls_decode_picture() and stored in the context. Found-by: Michael Niedermayer <michael@niedermayer.cc> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mjpegdec: Fix leak in case ICC array allocations fail partiallyAndreas Rheinhardt2021-04-03
| | | | | | | | | If only one of the two arrays used for the ICC profile could be successfully allocated, it might be overwritten and leak when the next ICC entry is encountered. Fix this by using a common struct, so that one has only one array to allocate. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mjpegdec: Check initializing Huffman tablesAndreas Rheinhardt2021-04-03
| | | | | Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mjpegdec: Fix leak in case of invalid external Huffman tablesAndreas Rheinhardt2021-04-03
| | | | | | | | | | | | | When using external Huffman tables fails during init, the decoder reverts back to using the default Huffman tables; and when doing so, the current VLC tables leak because init_default_huffman_tables() doesn't free them before overwriting them. Sample: samples.ffmpeg.org/archive/all/avi+mjpeg+pcm_s16le++mjpeg-interlace.avi Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc/mjpegdec: Decode format 211121 as YUV 4:4:4Carl Eugen Hoyos2021-03-23
| | | | Fixes ticket #8930.
* mjpegdec: handle lowres with AVID croppingAnton Khirnov2021-03-08
|
* Handle AVID MJPEG streams directly in the MJPEG decoder.Anton Khirnov2021-02-25
| | | | | | | | | | | | | | | | | | | | AVID streams - currently handled by the AVRN decoder - can be (depending on extradata contents) either MJPEG or raw video. To decode the MJPEG variant, the AVRN decoder currently instantiates a MJPEG decoder internally and forwards decoded frames to the caller (possibly after cropping them). This is suboptimal, because the AVRN decoder does not forward all the features of the internal MJPEG decoder, such as direct rendering. Handling such forwarding in a full and generic manner would be quite hard, so it is simpler to just handle those streams in the MJPEG decoder directly. The AVRN decoder, which now handles only the raw streams, can now be marked as supporting direct rendering. This also removes the last remaining internal use of the obsolete decoding API.
* avcodec/g2meet, mjpegdec: Factor out common VLC initialization codeAndreas Rheinhardt2021-02-23
| | | | | | | | | While just at it, remove the nb_codes parameter: It is redundant (the number of codes is implicitly contained in the array containing how many entries of a specific size there are) and for this reason it might even be wrong, so it is better to check what is actually used instead. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mjpegdec: Cleanup ff_smvjpeg_decoder()Michael Niedermayer2021-02-22
| | | | | | | | | | Fixes: memleaks Fixes: 28533/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMVJPEG_fuzzer-6242529653686272 Fixes: 30594/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMVJPEG_fuzzer-6549216035995648 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* mjpegdec: stop setting the QP tableAnton Khirnov2021-02-08
| | | | | | | MJPEG does not have a single quantiser scale, so this does not fit into the intended API use. This removes the last use of the long-deprecated QP table API.
* Mark some pointers as constAndreas Rheinhardt2021-01-01
| | | | | Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* lavc/mjpegdec: cosmetics, org->origAnton Khirnov2021-01-01
|
* avcodec/mjpegdec: stop setting AVFrame->best_effort_timestampJames Almer2020-12-13
| | | | | | It's now set by the generic decode code. Signed-off-by: James Almer <jamrial@gmail.com>
* smvjpegdec: merge into mjpegdecAnton Khirnov2020-12-10
| | | | | | | | | | | | | | | | | | | | | | | SMVJPEG stores frames as slices of a big JPEG image. The decoder is implemented as a wrapper that instantiates a full internal MJPEG decoder, then forwards the decoded frames with offset data pointers. This is unnecessarily complex and fragile, not supporting useful decoder capabilities like direct rendering. Re-implement the decoder inside the MJPEG decoder, which is accomplished by returning each decoded frame multiple times, setting cropping information appropriately on each instance. One peculiar aspect of the previous design is that since - the smvjpeg decoder returns one frame per input packet - there are multiple frames in each packets (the aformentioned slices) the demuxer needs to return each packet multiple times. This is now also eliminated - the demuxer now returns each packet exactly once, with the duration set to the number of frames it decodes to. This also removes one of the last remaining internal uses of the old video decoding API.
* mjpegdec: convert to receive_frame()Anton Khirnov2020-12-10
| | | | This will be useful in the following commit.
* avcodec/mjpegdec: Simplify creating VLC tableAndreas Rheinhardt2020-12-08
| | | | | | | | ff_init_vlc_from_lengths() can be used to offload the computation of the codes; it also allows to omit the check whether the codes are already properly ordered (they are). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mxpegdec: Fix memleaks upon init failureAndreas Rheinhardt2020-12-04
| | | | | Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mjpegdec: Fix memleak upon init failureAndreas Rheinhardt2020-12-04
| | | | | | | | | This affected all decoders that used ff_mjpeg_decode_init() as init function; and it also affected decoders that open jpeg decoders via ff_codec_open2_recursive() as well as MxPEG. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mjpegdec: Remove redundant initializationAndreas Rheinhardt2020-10-09
| | | | | | | | | Now that the correct number of codes is used, it is no longer necessary to initialize the lengths of the codes at all any more as the length of the actually used codes is set later anyway. Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mjpegdec: Remove use_static from build_vlc()Andreas Rheinhardt2020-10-09
| | | | | | | | | It is always zero; it referred to the INIT_VLC_USE_STATIC flag which has been removed in 595324e143b57a52e2329eb47b84395c70f93087. Reviewed-by: Paul B Mahol <onemda@gmail.com> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mjpegdec: Use correct number of codes when init default VLCsAndreas Rheinhardt2020-10-08
| | | | | | | | | | | | | | | | | | | | | | | | | Commit bbc0d0c1fe2b7ecdc4367295594f084f85ad22f5 made the mjpeg decoder use default Huffman tables when none are given, yet when initializing the default Huffman tables, it did not use the correct number of entries of the arrays used to initialize the tables, but instead it used the biggest entry + 1 (as if it were a continuous array 0..biggest entry). This worked because the ff_init_vlc_sparse() (and its predecessors) always skipped entries with a length of zero and the length of the corresponding elements was always initialized to zero with only the sizes of the actually existing elements being set to a size > 0 lateron. Yet since commit 1249698e1b424cff8e77e6a83cfdbc9d11e01aa7 this is no longer so, as build_vlc() actually read the array containing the values itself. This implies that the wrong length now leads to a read beyond the end of the given array; this could lead to crashs (but usually doesn't); it is detectable by ASAN* and this commit fixes it. *: AddressSanitizer: global-buffer-overflow on address xy ... xy is located 0 bytes to the right of global variable 'avpriv_mjpeg_val_ac_luminance' Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mjpegdec: Use correct number of codes for VLC tablesAndreas Rheinhardt2020-10-08
| | | | | | | | | | | | | | | | | | Commit 1249698e1b424cff8e77e6a83cfdbc9d11e01aa7 made ff_mjpeg_decode_dht() call build_vlc() with a wrong (too hight) number of codes. The reason it worked is that the lengths of the extraneous entries is initialized to zero and ff_init_vlc_sparse() ignores codes with a length of zero. But using a too high number of codes was nevertheless bad, because a) the assert in build_vlc() could have been triggered (namely if the real amount of codes is 256) and b) the loop in build_vlc() uses initialized data (leading to Valgrind errors [1]). Furthermore, the old code spend CPU cycles in said loop although the result won't be used anyway. [1]: http://fate.ffmpeg.org/report.cgi?slot=x86_64-archlinux-gcc-valgrind&time=20201008025137 Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mjpegdec: improve decoding of DNG filesPaul B Mahol2020-10-07
| | | | That have unused symbols coded in DHT.
* avcodec/mjpegdec: Limit bayer to single plane outputting formatMichael Niedermayer2020-07-05
| | | | | | | This reduces the number of paths reachable with DNG and should improve security Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavc: Rename hwaccel.h to hwconfig.hMark Thompson2020-04-26
| | | | | This already applied to decoders as well as hwaccels, and adding encoder support was going to make the name even more inaccurate.
* avcodec: Replace get_bits_long() by get_bits() where possibleMichael Niedermayer2019-12-31
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mjpegdec: Unify switch statementsAndreas Rheinhardt2019-09-18
| | | | | | | | | This has been forgotten in d5a3a20d. Found via PVS-Studio (see ticket #8156). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mjpegdec: Restore non bayer checks in ljpeg_decode_rgb_scan()Michael Niedermayer2019-09-13
| | | | | | | | | Fixes: out of array write Fixes: 17088/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEGLS_fuzzer-5654877765632000 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>
* avcodec/mjpegdec: Only allow 0x11110000 pix_fmt_id for bayer modeMichael Niedermayer2019-09-13
| | | | | | | | | | | Fixes: NULL pointer dereference Fixes: assertion failure Fixes: 17003/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MJPEG_fuzzer-5696929253556224 Fixes: 17039/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MJPEG_fuzzer-5651008134316032 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>
* lavc/mjpegdec: Skip unknown APPx marker on bayer imagesNick Renieris2019-09-02
| | | | | | | | Samples: - Embedded JPEG images in the DNG images here: https://www.photographyblog.com/previews/pentax_k1_photos Signed-off-by: Nick Renieris <velocityra@gmail.com>
* lavc/mjpegdec: Enable decoding of single-component bayer imagesNick Renieris2019-09-02
| | | | | | | | | Also, ensure no false positives when determining DNG bayer images, by setting them in tiff.c instead of relying on a heuristic. There's no way to determine this just from the JPEG data, so we have to pass this information from outside the MJPEG decoder. Signed-off-by: Nick Renieris <velocityra@gmail.com>
* lavc/mjpegdec: Decode Huffman-coded lossless JPEGs embedded in DNGsNick Renieris2019-09-02
| | | | | | | | | | | Main image data in DNGs is usually comprised of tiles, each of which is a Huffman-encoded lossless JPEG. Tested for ljpeg regressions with: `ffmpeg -f lavfi -i testsrc=d=1 -vcodec ljpeg test.avi` `ffmpeg test.avi out.avi` The modified code in ljpeg_decode_rgb_scan runs without issues. Signed-off-by: Nick Renieris <velocityra@gmail.com>
* lavc/mjpegdec: make code alignedZhong Li2019-07-01
| | | | | Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Zhong Li <zhong.li@intel.com>
* lavc/mjpegdec: replace number with marker nameZhong Li2019-07-01
| | | | | | Make it easier to read. Signed-off-by: Zhong Li <zhong.li@intel.com>
* avcodec/mjpegdec: Check for non ls PAL8Michael Niedermayer2019-06-12
| | | | | | | | Fixes: Null-dereference READ in av_malloc Fixes: 15002/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_THP_fuzzer-5643474625363968 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mjpegdec: Fix stereo3d memleakMichael Niedermayer2019-02-25
| | | | | | | Fixes: 12937/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_THP_fuzzer-5714945346371584 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mjpegdec: Fix indention of ljpeg_decode_yuv_scan()Michael Niedermayer2018-12-19
| | | | | Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mjpegdec: verify SOF len field validityMichael Niedermayer2018-12-19
| | | | | Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavc/mjpegdec: Interpret three-component Adobe transform 0 also as RGB.Carl Eugen Hoyos2018-12-18
| | | | | | While there, make a comparison with "RGB" more readable. Fixes ticket #7625.
* mjpegdec: Fill raw huffman tables with default values tooMark Thompson2018-11-18
| | | | | | These may be used by hwaccel decoders when the standard tables are not otherwise available. At the same time, clean up that code into an array so it's a little less repetitive.
* mjpeg: Use profile names in the encoder and decoderVittorio Giovara2018-11-05
|
* lavc/mjpegdec: Support 2:3 subsampling.Carl Eugen Hoyos2018-10-18
| | | | Fixes ticket #7495.
* avcodec/mjpegdec: simplify rgb index remapingMichael Niedermayer2018-09-12
|
* avcodec/mjpegdec: Check for odd progressive RGBMichael Niedermayer2018-07-08
| | | | | | | | Fixes: out of array access Fixes: 9225/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEGLS_fuzzer-5684770334834688 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mjpegdec: Check for end of bitstream in ljpeg_decode_rgb_scan()Michael Niedermayer2018-06-23
| | | | | | | | Fixes: Timeout Fixes: 8648/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MJPEG_fuzzer-5108395525799936 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mjpegdec: Fix integer overflow in ljpeg_decode_rgb_scan()Michael Niedermayer2018-06-06
| | | | | | | | Fixes: signed integer overflow: 32768 + 2147450880 cannot be represented in type 'int' Fixes: 7885/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_THP_fuzzer-5298834394578944 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mjpegdec: Check input buffer size.Michael Niedermayer2018-04-12
| | | | | | | | Fixes: Timeout Fixes: 6381/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEGLS_fuzzer-5665032743419904 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/nvdec: Implement mjpeg nvdec hwaccelPhilip Langdale2018-02-21
|