aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher R. Palmer <crpalmer@gmail.com>2017-05-24 06:21:08 -0400
committerChristopher R. Palmer <crpalmer@gmail.com>2017-05-24 06:21:08 -0400
commit1bd02b0021d8125b0b028cd95b51231c1373e493 (patch)
tree828f4073e77ecab24ab1b08bee6f73abdbc2b740
parent248cdbb33213983bafb430505acf15f7c55ec036 (diff)
parentb33d01d8a253028083df250b5d4a2e43e5560c64 (diff)
downloadandroid_external_ffmpeg-cm-14.1.tar.gz
android_external_ffmpeg-cm-14.1.tar.bz2
android_external_ffmpeg-cm-14.1.zip
Merge remote-tracking branch 'ffmpeg/release/3.0' into HEADcm-14.1
-rw-r--r--Changelog316
-rw-r--r--RELEASE2
-rw-r--r--cmdutils.c4
-rw-r--r--cmdutils.h4
-rwxr-xr-xconfigure18
-rw-r--r--doc/Doxyfile2
-rw-r--r--doc/developer.texi5
-rw-r--r--doc/examples/demuxing_decoding.c5
-rw-r--r--doc/ffmpeg.texi18
-rw-r--r--doc/ffplay.texi6
-rw-r--r--doc/ffprobe.texi10
-rw-r--r--doc/formats.texi4
-rw-r--r--ffmpeg.c7
-rw-r--r--ffmpeg_opt.c4
-rw-r--r--ffserver.c5
-rw-r--r--libavcodec/8bps.c7
-rw-r--r--libavcodec/aacdec.c4
-rw-r--r--libavcodec/aacdec_fixed.c16
-rw-r--r--libavcodec/aacdec_template.c6
-rw-r--r--libavcodec/aacps.c2
-rw-r--r--libavcodec/aacsbr_template.c26
-rw-r--r--libavcodec/ac3dec.c29
-rw-r--r--libavcodec/ac3dec.h2
-rw-r--r--libavcodec/adxdec.c2
-rw-r--r--libavcodec/amrwbdec.c6
-rw-r--r--libavcodec/asvenc.c2
-rw-r--r--libavcodec/avcodec.h10
-rw-r--r--libavcodec/avpacket.c14
-rw-r--r--libavcodec/bmvvideo.c2
-rw-r--r--libavcodec/cavs.c11
-rw-r--r--libavcodec/cavsdec.c8
-rw-r--r--libavcodec/cdxl.c6
-rw-r--r--libavcodec/cinepak.c7
-rw-r--r--libavcodec/cllc.c29
-rw-r--r--libavcodec/dcadsp.c2
-rw-r--r--libavcodec/dds.c4
-rw-r--r--libavcodec/dfa.c7
-rw-r--r--libavcodec/diracdec.c6
-rw-r--r--libavcodec/dss_sp.c8
-rw-r--r--libavcodec/dvbsubdec.c14
-rw-r--r--libavcodec/dvdsubdec.c11
-rw-r--r--libavcodec/eac3dec.c8
-rw-r--r--libavcodec/eamad.c2
-rw-r--r--libavcodec/eatqi.c2
-rw-r--r--libavcodec/escape124.c4
-rw-r--r--libavcodec/exr.c4
-rw-r--r--libavcodec/ffv1dec.c11
-rw-r--r--libavcodec/ffv1enc.c18
-rw-r--r--libavcodec/fic.c4
-rw-r--r--libavcodec/flac_parser.c2
-rw-r--r--libavcodec/flacdec.c9
-rw-r--r--libavcodec/flacdsp_template.c2
-rw-r--r--libavcodec/flicvideo.c5
-rw-r--r--libavcodec/g722.c8
-rw-r--r--libavcodec/g723_1.c18
-rw-r--r--libavcodec/g723_1.h2
-rw-r--r--libavcodec/g723_1dec.c18
-rw-r--r--libavcodec/g726.c2
-rw-r--r--libavcodec/get_bits.h4
-rw-r--r--libavcodec/h264.c4
-rw-r--r--libavcodec/h264_cabac.c2
-rw-r--r--libavcodec/h264_cavlc.c2
-rw-r--r--libavcodec/h264_direct.c2
-rw-r--r--libavcodec/h264_mvpred.h4
-rw-r--r--libavcodec/hevc_sei.c11
-rw-r--r--libavcodec/hq_hqa.c6
-rw-r--r--libavcodec/hqxdsp.c16
-rw-r--r--libavcodec/htmlsubtitles.c14
-rw-r--r--libavcodec/htmlsubtitles.h2
-rw-r--r--libavcodec/idcinvideo.c7
-rw-r--r--libavcodec/indeo2.c13
-rw-r--r--libavcodec/interplayacm.c19
-rw-r--r--libavcodec/interplayvideo.c16
-rw-r--r--libavcodec/ituh263dec.c3
-rw-r--r--libavcodec/ivi_dsp.c10
-rw-r--r--libavcodec/kmvc.c7
-rw-r--r--libavcodec/lagarith.c6
-rw-r--r--libavcodec/libopenjpegdec.c2
-rw-r--r--libavcodec/libopenjpegenc.c59
-rw-r--r--libavcodec/libopusdec.c7
-rw-r--r--libavcodec/libschroedingerdec.c18
-rw-r--r--libavcodec/lzf.c2
-rw-r--r--libavcodec/mdec.c6
-rw-r--r--libavcodec/mimic.c2
-rw-r--r--libavcodec/mjpegdec.c21
-rw-r--r--libavcodec/mlpdec.c17
-rw-r--r--libavcodec/mlpdsp.c4
-rw-r--r--libavcodec/movtextdec.c19
-rw-r--r--libavcodec/mpeg12dec.c18
-rw-r--r--libavcodec/mpeg4videodec.c149
-rw-r--r--libavcodec/mpegaudio_parser.c2
-rw-r--r--libavcodec/mpegaudiodec_template.c4
-rw-r--r--libavcodec/mpegvideo_enc.c2
-rw-r--r--libavcodec/mpegvideo_motion.c8
-rw-r--r--libavcodec/msmpeg4dec.c17
-rw-r--r--libavcodec/msrle.c7
-rw-r--r--libavcodec/mss2.c8
-rw-r--r--libavcodec/mss3.c3
-rw-r--r--libavcodec/mss34dsp.c44
-rw-r--r--libavcodec/msvideo1.c13
-rw-r--r--libavcodec/nellymoser.c4
-rw-r--r--libavcodec/options.c41
-rw-r--r--libavcodec/opus_silk.c3
-rw-r--r--libavcodec/pgssubdec.c14
-rw-r--r--libavcodec/pictordec.c8
-rw-r--r--libavcodec/pngdec.c37
-rw-r--r--libavcodec/pnmdec.c10
-rw-r--r--libavcodec/ppc/pixblockdsp.c17
-rw-r--r--libavcodec/proresdec_lgpl.c2
-rw-r--r--libavcodec/qpeg.c7
-rw-r--r--libavcodec/qtrle.c7
-rw-r--r--libavcodec/ra144.c2
-rw-r--r--libavcodec/rawdec.c7
-rw-r--r--libavcodec/rscc.c6
-rw-r--r--libavcodec/rv34.c44
-rw-r--r--libavcodec/rv40.c4
-rw-r--r--libavcodec/rv40dsp.c2
-rw-r--r--libavcodec/s302m.c8
-rw-r--r--libavcodec/shorten.c5
-rw-r--r--libavcodec/smacker.c12
-rw-r--r--libavcodec/smvjpegdec.c4
-rw-r--r--libavcodec/snowdec.c9
-rw-r--r--libavcodec/srtdec.c8
-rw-r--r--libavcodec/sunrast.c2
-rw-r--r--libavcodec/svq3.c44
-rw-r--r--libavcodec/takdec.c14
-rw-r--r--libavcodec/targa_y216dec.c3
-rw-r--r--libavcodec/texturedsp.c6
-rw-r--r--libavcodec/tiertexseqv.c5
-rw-r--r--libavcodec/tiff.c20
-rw-r--r--libavcodec/truemotion1.c10
-rw-r--r--libavcodec/tscc.c7
-rw-r--r--libavcodec/utils.c9
-rw-r--r--libavcodec/vdpau_hevc.c2
-rw-r--r--libavcodec/vp3.c13
-rw-r--r--libavcodec/vp3dsp.c2
-rw-r--r--libavcodec/vp5.c13
-rw-r--r--libavcodec/vp56.c97
-rw-r--r--libavcodec/vp56.h7
-rw-r--r--libavcodec/vp56rac.c5
-rw-r--r--libavcodec/vp6.c41
-rw-r--r--libavcodec/vp8.c49
-rw-r--r--libavcodec/vp8.h2
-rw-r--r--libavcodec/vp8dsp.c38
-rw-r--r--libavcodec/vp9.c14
-rw-r--r--libavcodec/wavpack.c10
-rw-r--r--libavcodec/webp.c39
-rw-r--r--libavcodec/wmv2dsp.c8
-rw-r--r--libavcodec/wnv1.c2
-rw-r--r--libavcodec/x86/vc1dsp_init.c6
-rw-r--r--libavcodec/xwddec.c4
-rw-r--r--libavcodec/y41pdec.c2
-rw-r--r--libavfilter/af_pan.c4
-rw-r--r--libavfilter/af_sofalizer.c2
-rw-r--r--libavfilter/avfiltergraph.c2
-rw-r--r--libavfilter/vf_blackframe.c4
-rw-r--r--libavfilter/vf_uspp.c4
-rw-r--r--libavformat/apngdec.c2
-rw-r--r--libavformat/avformat.h7
-rw-r--r--libavformat/avidec.c3
-rw-r--r--libavformat/concatdec.c7
-rw-r--r--libavformat/dcstr.c8
-rw-r--r--libavformat/ffmdec.c8
-rw-r--r--libavformat/filmstripdec.c7
-rw-r--r--libavformat/flacdec.c3
-rw-r--r--libavformat/http.c120
-rw-r--r--libavformat/icodec.c20
-rw-r--r--libavformat/idroqdec.c3
-rw-r--r--libavformat/matroskadec.c15
-rw-r--r--libavformat/mov.c12
-rw-r--r--libavformat/mpeg.c4
-rw-r--r--libavformat/mpegts.c13
-rw-r--r--libavformat/mxfdec.c6
-rw-r--r--libavformat/oggdec.c2
-rw-r--r--libavformat/oggparsedaala.c3
-rw-r--r--libavformat/oggparsespeex.c7
-rw-r--r--libavformat/options_table.h1
-rw-r--r--libavformat/rsd.c4
-rw-r--r--libavformat/rtmppkt.c8
-rw-r--r--libavformat/sbgdec.c2
-rw-r--r--libavformat/utils.c18
-rw-r--r--libavformat/wavdec.c2
-rw-r--r--libavformat/webmdashenc.c10
-rw-r--r--libavutil/imgutils.c29
-rw-r--r--libavutil/imgutils.h14
-rw-r--r--libavutil/internal.h14
-rw-r--r--libavutil/mips/generic_macros_msa.h12
-rw-r--r--libavutil/random_seed.c10
-rw-r--r--libavutil/softfloat.h17
-rw-r--r--libswresample/resample.c16
-rw-r--r--libswscale/swscale-test.c4
-rw-r--r--tests/ref/fate/vp52
-rw-r--r--tools/ismindex.c2
-rw-r--r--tools/zmqsend.c2
194 files changed, 1780 insertions, 738 deletions
diff --git a/Changelog b/Changelog
index a5bcb37b25..cd39890926 100644
--- a/Changelog
+++ b/Changelog
@@ -1,7 +1,323 @@
Entries are sorted chronologically from oldest to youngest within each release,
releases are sorted from youngest to oldest.
+version 3.0.8
+- avcodec/aacdec: Fix runtime error: signed integer overflow: 2147483520 + 255 cannot be represented in type 'int'
+- avcodec/aacdec_template: Fix fixed point scale in decode_cce()
+- avcodec/flicvideo: Check frame_size before decrementing
+- avcodec/mlpdec: Fix runtime error: left shift of negative value -1
+- avcodec/takdec: Fix runtime error: left shift of negative value -42
+- avcodec/hq_hqa: Fix: runtime error: signed integer overflow: -255 * 10180917 cannot be represented in type 'int'
+- avcodec/truemotion1: Fix multiple runtime error: signed integer overflow: 1246906962 * 2 cannot be represented in type 'int'
+- avcodec/svq3: Fix runtime error: left shift of negative value -6
+- avcodec/tiff: reset sampling[] if its invalid
+- avcodec/aacps: Fix undefined behavior
+- avcodec/opus_silk: Fix integer overflow and out of array read
+- avcodec/flacdec: Return error code instead of 0 for failures
+- avcodec/snowdec: Check width
+- avcodec/webp: Update canvas size in vp8_lossy_decode_frame() as in vp8_lossless_decode_frame()
+- avcodec/webp: Factor update_canvas_size() out
+- avcodec/cllc: Check prefix
+- avcodec/rscc: Check pixel_size for overflow
+- avcodec/dds: Fix runtime error: left shift of 210 by 24 places cannot be represented in type 'int'
+- avcodec/mpeg4videodec: Clear sprite wraping on unsupported cases in VOP decode
+- avcodec/ac3dec: Fix: runtime error: index -1 out of bounds for type 'INTFLOAT [2]'
+- avcodec/hqxdsp: Fix runtime error: signed integer overflow: -196264 * 11585 cannot be represented in type 'int'
+- avcodec/g723_1dec: Fix LCG type
+- libswscale/tests/swscale: Fix uninitialized variables
+- avcodec/ffv1dec: Fix runtime error: signed integer overflow: 1550964438 + 1550964438 cannot be represented in type 'int'
+- avcodec/webp: Fix signedness in prefix_code check
+- avcodec/svq3: Fix runtime error: signed integer overflow: 169 * 12717677 cannot be represented in type 'int'
+- avcodec/mlpdec: Check that there is enough data for headers
+- avcodec/ac3dec: Keep track of band structure
+- avcodec/webp: Add missing input padding
+- avcodec/aacdec_fixed: Fix runtime error: left shift of negative value -1
+- avcodec/aacsbr_template: Do not change bs_num_env before its checked
+- avcodec/mlp: Fix multiple runtime error: left shift of negative value -1
+- avcodec/vp8dsp: vp7_luma_dc_wht_c: Fix multiple runtime error: signed integer overflow: -1366381240 + -1262413604 cannot be represented in type 'int'
+- avcodec/avcodec: Limit the number of side data elements per packet
+- avcodec/texturedsp: Fix runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
+- avcodec/g723_1dec: Fix runtime error: left shift of negative value -1
+- avcodec/wmv2dsp: Fix runtime error: signed integer overflow: 181 * -17047030 cannot be represented in type 'int'
+- avcodec/diracdec: Fix Assertion frame->buf[0] failed at libavcodec/decode.c:610
+- avcodec/msmpeg4dec: Check for cbpy VLC errors
+- avcodec/cllc: Check num_bits
+- avcodec/cllc: Factor VLC_BITS/DEPTH out, do not use repeated literal numbers
+- avcodec/dvbsubdec: Check entry_id
+- avcodec/aacdec_fixed: Fix multiple shift exponent 33 is too large for 32-bit type 'int'
+- avcodec/mpeg12dec: Fixes runtime error: division by zero
+- avcodec/webp: Always set pix_fmt
+- avfilter/vf_uspp: Fix currently unused input frame dimensions
+- avcodec/truemotion1: Fix multiple runtime error: left shift of negative value -1
+- avcodec/eatqi: Fix runtime error: signed integer overflow: 4466147 * 1075 cannot be represented in type 'int'
+- avcodec/dss_sp: Fix runtime error: signed integer overflow: 2147481189 + 4096 cannot be represented in type 'int'
+- avformat/wavdec: Check chunk_size
+- avcodec/cavs: Check updated MV
+- avcodec/y41pdec: Fix width in input buffer size check
+- avcodec/svq3: Fix multiple runtime error: signed integer overflow: -237341 * 24552 cannot be represented in type 'int'
+- avcodec/texturedsp: Fix runtime error: left shift of 218 by 24 places cannot be represented in type 'int'
+- avcodec/lagarith: Check scale_factor
+- avcodec/lagarith: Fix runtime error: left shift of negative value -1
+- avcodec/takdec: Fix multiple runtime error: left shift of negative value -1
+- avcodec/indeo2: Check for invalid VLCs
+- avcodec/g723_1dec: Fix several integer related cases of undefined behaviour
+- avcodec/htmlsubtitles: Check for string truncation and return error
+- avcodec/bmvvideo: Fix runtime error: left shift of 137 by 24 places cannot be represented in type 'int'
+- avcodec/dss_sp: Fix multiple runtime error: signed integer overflow: -15699 * -164039 cannot be represented in type 'int'
+- avcodec/dvbsubdec: check region dimensions
+- avcodec/vp8dsp: Fixes: runtime error: signed integer overflow: 1330143360 - -1023040530 cannot be represented in type 'int'
+- avcodec/hqxdsp: Fix multiple runtime error: signed integer overflow: 248220 * 21407 cannot be represented in type 'int' in idct_col()
+- avcodec/cavsdec: Check sym_factor
+- avcodec/cdxl: Check format for BGR24
+- avcodec/ffv1dec: Fix copying planes of paletted formats
+- avcodec/wmv2dsp: Fix runtime error: signed integer overflow: 181 * -12156865 cannot be represented in type 'int'
+- avcodec/xwddec: Check bpp more completely
+- avcodec/s302m: Fix left shift of 8 by 28 places cannot be represented in type 'int'
+- avcodec/eamad: Fix runtime error: signed integer overflow: 49674 * 49858 cannot be represented in type 'int'
+- avcodec/g726: Fix runtime error: left shift of negative value -2
+- avcodec/ra144: Fix runtime error: left shift of negative value -798
+- avcodec/mss34dsp: Fix multiple signed integer overflow
+- avcodec/targa_y216dec: Fix width type
+- avcodec/texturedsp: Fix multiple runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
+- avcodec/ivi_dsp: Fix multiple left shift of negative value -2
+- avcodec/svq3: Fix multiple runtime error: signed integer overflow: 44161 * 61694 cannot be represented in type 'int'
+- avcodec/msmpeg4dec: Correct table depth
+- avcodec/dds: Fix runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
+- avcodec/cdxl: Check format parameter
+- avutil/softfloat: Fix overflow in av_div_sf()
+- avcodec/hq_hqa: Fix runtime error: left shift of negative value -207
+- avcodec/mss3: Change types in rac_get_model_sym() to match the types they are initialized from
+- avcodec/shorten: Check k in get_uint()
+- avcodec/webp: Fix null pointer dereference
+- avcodec/dfa: Fix signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'
+- avcodec/g723_1: Fix multiple runtime error: left shift of negative value
+- avcodec/mimic: Fix runtime error: left shift of negative value -1
+- avcodec/fic: Fix multiple left shift of negative value -15
+- avcodec/mlpdec: Fix runtime error: left shift of negative value -22
+- avcodec/snowdec: Check qbias
+- avutil/softfloat: Fix multiple runtime error: left shift of negative value -8
+- avcodec/aacsbr_template: Do not leave bs_num_env invalid
+- avcodec/mdec: Fix signed integer overflow: 28835400 * 83 cannot be represented in type 'int'
+- avcodec/dfa: Fix off by 1 error
+- avcodec/nellymoser: Fix multiple left shift of negative value -8591
+- avcodec/cdxl: Fix signed integer overflow: 14243456 * 164 cannot be represented in type 'int'
+- avcodec/g722: Fix multiple runtime error: left shift of negative value -1
+- avcodec/dss_sp: Fix multiple left shift of negative value -466
+- avcodec/wnv1: Fix runtime error: left shift of negative value -1
+- avcodec/tiertexseqv: set the fixed dimenasions, do not depend on the demuxer doing so
+- avcodec/mjpegdec: Fix runtime error: signed integer overflow: -24543 * 2031616 cannot be represented in type 'int'
+- avcodec/cavsdec: Fix undefined behavior from integer overflow
+- avcodec/dvdsubdec: Fix runtime error: left shift of 242 by 24 places cannot be represented in type 'int'
+- libavcodec/mpeg4videodec: Convert sprite_offset to 64bit
+- avcodec/pngdec: Use ff_set_dimensions()
+- avcodec/msvideo1: Check buffer size before re-getting the frame
+- avcodec/h264_cavlc: Fix undefined behavior on qscale overflow
+- avcodec/dcadsp: Fix runtime error: signed integer overflow
+- avcodec/svq3: Increase offsets to prevent integer overflows
+- avcodec/indeo2: Check remaining bits in ir2_decode_plane()
+- avcodec/vp3: Check remaining bits in unpack_dct_coeffs()
+- doc/developer: Add terse documentation of assumed C implementation defined behavior
+- avcodec/mdec: Fix runtime error: left shift of negative value -127
+- avcodec/x86/vc1dsp_init: Fix build failure with --disable-optimizations and clang
+- libavcodec/exr : fix float to uint16 conversion for negative float value
+- avformat/webmdashenc: Validate the 'streams' adaptation sets parameter
+- avformat/webmdashenc: Require the 'adaptation_sets' option to be set
+- avcodec/dvdsubdec: Fixes 2 runtime error: left shift of 170 by 24 places cannot be represented in type 'int'
+- avformat/oggparsedaala: Do not leave an invalid value in gpshift
+- avformat/oggparsedaala: Check duration for AV_NOPTS_VALUE
+- avfilter/af_sofalizer: Fix bad shift
+- avfilter/avfiltergraph: Add assert to write down in machine readable form what is assumed about sample rates in swap_samplerates_on_filter()
+- avcodec/tiff: Perform multiply in tiff_unpack_lzma() as 64bit
+- avcodec/vdpau_hevc: Fix potential out-of-bounds write
+- avcodec/tiff: Check geotag count for being non zero
+- avcodec/vp56: Check avctx->error_concealment before enabling EC
+- avcodec/tiff: Check stripsize strippos for overflow
+- avcodec/mpegaudiodec_template: Make l3_unscale() work with e=0
+- avcodec/tiff: Check for multiple geo key directories
+- avcodec/wavpack: Fix runtime error: shift exponent 32 is too large for 32-bit type 'int'
+- avcodec/rv34: Fix runtime error: signed integer overflow: 36880 * 66288 cannot be represented in type 'int'
+- avcodec/amrwbdec: Fix runtime error: left shift of negative value -1
+- avcodec/mpeg4videodec: Fix runtime error: signed integer overflow: -135088512 * 16 cannot be represented in type 'int'
+- avcodec/h264_mvpred: Fix runtime error: left shift of negative value -1
+- avcodec/mjpegdec: Fix runtime error: left shift of negative value -127
+- avcodec/wavpack: Fix runtime error: left shift of negative value -5
+- avcodec/wavpack: Fix runtime error: left shift of negative value -2
+- avcodec/mpeg4videodec: Fix runtime error: signed integer overflow: 134527392 * 16 cannot be represented in type 'int'
+- avcodec/mpeg12dec: Fix runtime error: left shift of negative value -13
+- avcodec/h264_mvpred: Fix multiple runtime error: left shift of negative value
+- avcodec/adxdec: Fix runtime error: left shift of negative value -1
+- avcodec/mpeg4videodec: Improve the overflow checks in mpeg4_decode_sprite_trajectory()
+- avcodec/mjpegdec: Fix runtime error: left shift of negative value -511
+- avcodec/h264_direct: Fix runtime error: left shift of negative value -14
+- avcodec/pictordec: Check plane value before doing value/mask computations
+- avcodec/mpeg4videodec: Fix runtime error: left shift of negative value -2650
+- avcodec/eac3dec: Fix runtime error: left shift of negative value -3
+- avcodec/mpeg12dec: Fix runtime error: left shift of negative value -2
+- avcodec/mpeg4videodec: Check the other 3 sprite points for intermediate overflows
+- avcodec/mpeg4videodec: Check sprite_offset in addition to shifts
+- avcodec/mpeg4video: Fix runtime error: left shift of negative value
+- avcodec/ituh263dec: Fix runtime error: left shift of negative value -22
+- avcodec/rv40: Fix runtime error: left shift of negative value
+- avcodec/h264_cabac: runtime error: signed integer overflow: 2147483647 + 14 cannot be represented in type 'int'
+- avcodec/mpeg4videodec: Fix runtime error: shift exponent -2 is negative
+- avcodec/mjpegdec: Fix runtime error: left shift of negative value -507
+- avcodec/eac3dec: Fix runtime error: left shift of negative value
+- avcodec/htmlsubtitles: Fix reading one byte beyond the array
+- avcodec/vp6: clear dimensions on failed resolution change in vp6_parse_header()
+- avcodec/vp56: Reset have_undamaged_frame on resolution changes
+- avcodec/vp8: Fix hang with slice threads
+- avcodec/vp8: Check for the bitstream end per MB in decode_mb_row_no_filter()
+- avcodec/vp568: Check that there is enough data for ff_vp56_init_range_decoder()
+- avcodec/vp8: remove redundant check
+- avcodec/vp56: Require a correctly decoded frame before using vp56_conceal_mb()
+- avcodec/vp3: Do not return random positive values but the buf size
+- avcodec/vp8: Check for bitsteam end in decode_mb_row_no_filter()
+- avcodec/vp56: Factorize vp56_render_mb() out
+- avcodec/vp3dsp: Fix multiple signed integer overflow: 46341 * 47523 cannot be represented in type 'int'
+- Add CHECK/SUINT code
+- avcodec/mpeg12dec: Fix runtime error: left shift of negative value -1
+- avcodec/vp56: Clear dimensions in case of failure in the middle of a resolution change
+- avcodec/vp56: Implement very basic error concealment
+- avcodec/amrwbdec: Fix 2 runtime errors: left shift of negative value -1
+- avcodec/pngdec: Fix runtime error: left shift of 152 by 24 places cannot be represented in type 'int'
+- avcodec/vp56: Fix sign typo
+- avcodec/mpegaudiodec_template: Correct return code on id3 tag discarding
+- avcodec/rv34: Simplify and factor get_slice_offset() code
+- avcodec/pictordec: Do not read more than nb_planes
+- avcodec/srtdec: Fix signed integer overflow: 1811992524 * 384 cannot be represented in type 'int'
+- avcodec/pngdec: Check bit depth for validity
+- avcodec/mpeg12dec: Fix runtime error: left shift of negative value
+- avcodec/wavpacl: Fix runtime error: left shift of negative value -1
+- avformat/http: Check for truncated buffers in http_connect()
+- avformat/apng: fix setting frame delay when max_fps is set to no limit
+- swresample/resample: free existing ResampleContext on reinit
+- swresample/resample: move resample_free() higher in the file
+- lavf/mpeg: Initialize a stack variable used by memcmp().
+- lavc/avpacket: Initialize a variable in error path.
+
+version 3.0.7
+- avcodec/h264_slice: Clear ref_counts on redundant slices
+- lavf/mov.c: Avoid heap allocation wrap in mov_read_uuid
+- lavf/mov.c: Avoid heap allocation wrap in mov_read_hdlr
+- avcodec/pictordec: Fix logic error
+- avcodec/movtextdec: Fix decode_styl() cleanup
+- lavf/matroskadec: fix is_keyframe for early Blocks
+
+version 3.0.6:
+- avcodec/pngdec: Check trns more completely
+- avcodec/interplayvideo: Move parameter change check up
+- avcodec/mjpegdec: Check for for the bitstream end in mjpeg_decode_scan_progressive_ac()
+- avformat/flacdec: Check avio_read result when reading flac block header.
+- avcodec/utils: correct align value for interplay
+- avcodec/vp56: Check for the bitstream end, pass error codes on
+- avcodec/mjpegdec: Check remaining bitstream in ljpeg_decode_yuv_scan()
+- avcodec/pngdec: Fix off by 1 size in decode_zbuf()
+- avformat/avidec: skip odml master index chunks in avi_sync
+- avcodec/mjpegdec: Check for rgb before flipping
+- avutil/random_seed: Reduce the time needed on systems with very low precision clock()
+- avutil/random_seed: Improve get_generic_seed() with higher precision clock()
+- avformat/utils: Print verbose error message if stream count exceeds max_streams
+- avformat/options_table: Set the default maximum number of streams to 1000
+- pgssubdec: reset rle_data_len/rle_remaining_len on allocation error
+- avutil: Add av_image_check_size2()
+- avformat: Add max_streams option
+- avcodec/ffv1enc: Allocate smaller packet if the worst case size cannot be allocated
+- avcodec/mpeg4videodec: Fix undefined shifts in mpeg4_decode_sprite_trajectory()
+- avformat/oggdec: Skip streams in duration correction that did not had their duration set.
+- avcodec/ffv1enc: Fix size of first slice
+
+
+version 3.0.5:
+- configure: check for strtoull on msvc
+- http: move chunk handling from http_read_stream() to http_buf_read().
+- http: make length/offset-related variables unsigned.
+- ffserver: Check chunk size
+- Avoid using the term "file" and prefer "url" in some docs and comments
+- avformat/rtmppkt: Check for packet size mismatches
+- zmqsend: Initialize ret to 0
+- avcodec/rawdec: check for side data before checking its size
+- avcodec/flacdec: Fix undefined shift in decode_subframe()
+- avcodec/get_bits: Fix get_sbits_long(0)
+- avformat/ffmdec: Check media type for chunks
+- avcodec/flacdec: Fix signed integer overflow in decode_subframe_fixed()
+- avcodec/flacdsp_template: Fix undefined shift in flac_decorrelate_indep_c
+- avformat/oggparsespeex: Check frames_per_packet and packet_size
+- avformat/utils: Check start/end before computing duration in update_stream_timings()
+- avcodec/flac_parser: Update nb_headers_buffered
+- avformat/idroqdec: Check chunk_size for being too large
+- avformat/mpeg: Adjust vid probe threshold to correct mis-detection
+- avcodec/rv40: Test remaining space in loop of get_dimension()
+- avcodec/ituh263dec: Avoid spending a long time in slice sync
+- avcodec/movtextdec: Add error message for tsmb_size check
+- avcodec/movtextdec: Fix tsmb_size check==0 check
+- avcodec/movtextdec: Fix potential integer overflow
+- avcodec/sunrast: Fix input buffer pointer check
+- avcodec/tscc: Check side data size before use
+- avcodec/rawdec: Check side data size before use
+- avcodec/msvideo1: Check side data size before use
+- avcodec/qpeg: Check side data size before use
+- avcodec/qtrle: Check side data size before use
+- avcodec/msrle: Check side data size before use
+- avcodec/kmvc: Check side data size before use
+- avcodec/idcinvideo: Check side data size before use
+- avcodec/cinepak: Check side data size before use
+- avcodec/8bps: Check side data size before use
+- avcodec/dvdsubdec: Fix off by 1 error
+- avcodec/dvdsubdec: Fix buf_size check
+- vp9: change order of operations in adapt_prob().
+- avcodec/interplayvideo: Check side data size before use
+- avformat/mxfdec: Check size to avoid integer overflow in mxf_read_utf16_string()
+- avcodec/mpegvideo_enc: Clear mmx state in ff_mpv_reallocate_putbitbuffer()
+- avcodec/utils: Clear MMX state before returning from avcodec_default_execute*()
+- avformat/icodec: Fix crash probing fuzzed file
+- dcstr: fix division by zero
+- rsd: limit number of channels
+- mss2: only use error correction for matching block counts
+- softfloat: decrease MIN_EXP to cover full float range
+- libopusdec: default to stereo for invalid number of channels
+- pgssubdec: only set w/h/linesize when allocating data
+- sbgdec: prevent NULL pointer access
+- smacker: limit recursion depth of smacker_decode_bigtree
+- mxfdec: fix NULL pointer dereference in mxf_read_packet_old
+- libschroedingerdec: fix leaking of framewithpts
+- libschroedingerdec: don't produce empty frames
+- softfloat: handle -INT_MAX correctly
+- filmstripdec: correctly check image dimensions
+- pnmdec: make sure v is capped by maxval
+- smvjpegdec: make sure cur_frame is not negative
+- icodec: correctly check avio_read return value
+- dvbsubdec: fix division by zero in compute_default_clut
+- proresdec_lgpl: explicitly check coff[3] against slice_data_size
+- escape124: reject codebook size 0
+- icodec: add ico_read_close to fix leaking ico->images
+- icodec: fix leaking pkt on error
+- mpegts: prevent division by zero
+- matroskadec: fix NULL pointer dereference in webm_dash_manifest_read_header
+- mpegaudio_parser: don't return AVERROR_PATCHWELCOME
+- mxfdec: fix NULL pointer dereference
+- lzf: update pointer p after realloc
+- diracdec: check return code of get_buffer_with_edge
+- ppc: pixblockdsp: do unaligned block accesses correctly again
+- interplayacm: increase bitstream buffer size by AV_INPUT_BUFFER_PADDING_SIZE
+- interplayacm: validate number of channels
+- interplayacm: check for too large b
+- mpeg12dec: unref discarded picture from extradata
+- cavsdec: unref frame before referencing again
+- avformat: prevent triggering request_probe assert in ff_read_packet
+- avcodec/avpacket: fix leak on realloc in av_packet_add_side_data()
+
+
version 3.0.4:
+- libopenjpegenc: fix out-of-bounds reads when filling the edges
+- libopenjpegenc: stop reusing image data buffer for openjpeg 2
+- configure: fix detection of libopenjpeg
+- cmdutils: fix typos
+- lavfi: fix typos
+- lavc: fix typos
+- tools: fix grammar error
+- ffmpeg: remove unused and errorneous AVFrame timestamp check
+- Support for MIPS cpu P6600
+- avutil/mips/generic_macros_msa: rename macro variable which causes segfault for mips r
- avformat/avidec: Check nb_streams in read_gab2_sub()
- avformat/avidec: Remove ancient assert
- avformat/avidec: Fix memleak with dv in avi
diff --git a/RELEASE b/RELEASE
index b0f2dcb32f..67786e246e 100644
--- a/RELEASE
+++ b/RELEASE
@@ -1 +1 @@
-3.0.4
+3.0.8
diff --git a/cmdutils.c b/cmdutils.c
index 3bb8bde3e9..476c85894c 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -2111,7 +2111,7 @@ static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts)
if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
return AVERROR(EINVAL);
- printf("Audo-detected sources for %s:\n", fmt->name);
+ printf("Auto-detected sources for %s:\n", fmt->name);
if (!fmt->get_device_list) {
ret = AVERROR(ENOSYS);
printf("Cannot list sources. Not implemented.\n");
@@ -2141,7 +2141,7 @@ static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts)
if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
return AVERROR(EINVAL);
- printf("Audo-detected sinks for %s:\n", fmt->name);
+ printf("Auto-detected sinks for %s:\n", fmt->name);
if (!fmt->get_device_list) {
ret = AVERROR(ENOSYS);
printf("Cannot list sinks. Not implemented.\n");
diff --git a/cmdutils.h b/cmdutils.h
index 67bf4848b7..1b96aa48d1 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -450,13 +450,13 @@ int show_devices(void *optctx, const char *opt, const char *arg);
#if CONFIG_AVDEVICE
/**
- * Print a listing containing audodetected sinks of the output device.
+ * Print a listing containing autodetected sinks of the output device.
* Device name with options may be passed as an argument to limit results.
*/
int show_sinks(void *optctx, const char *opt, const char *arg);
/**
- * Print a listing containing audodetected sources of the input device.
+ * Print a listing containing autodetected sources of the input device.
* Device name with options may be passed as an argument to limit results.
*/
int show_sources(void *optctx, const char *opt, const char *arg);
diff --git a/configure b/configure
index c9c139e7aa..090a938136 100755
--- a/configure
+++ b/configure
@@ -4189,7 +4189,7 @@ elif enabled mips; then
enable mips32r2
disable msa
;;
- p5600|i6400)
+ p5600|i6400|p6600)
disable mipsdsp
disable mipsdspr2
;;
@@ -4254,6 +4254,10 @@ elif enabled mips; then
enable mips64r6
check_cflags "-mtune=i6400 -mabi=64" && check_cflags "-msched-weight -mload-store-pairs -funroll-loops" && check_ldflags "-mabi=64"
;;
+ p6600)
+ enable mips64r6
+ check_cflags "-mtune=p6600 -mabi=64" && check_cflags "-msched-weight -mload-store-pairs -funroll-loops" && check_ldflags "-mabi=64"
+ ;;
esac
else
# We do not disable anything. Is up to the user to disable the unwanted features.
@@ -5481,10 +5485,11 @@ enabled libopencv && { check_header opencv2/core/core_c.h &&
require_pkg_config opencv opencv2/core/core_c.h cvCreateImageHeader ||
require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader; }
enabled libopenh264 && require_pkg_config openh264 wels/codec_api.h WelsGetCodecVersion
-enabled libopenjpeg && { check_lib openjpeg-2.1/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC ||
- check_lib openjpeg-2.0/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC ||
- check_lib openjpeg-1.5/openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC ||
- check_lib openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC ||
+enabled libopenjpeg && { { check_lib2 openjpeg-2.1/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
+ check_lib2 openjpeg-2.1/openjpeg.h opj_version -lopenjp2 ||
+ { check_lib2 openjpeg-2.0/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
+ { check_lib2 openjpeg-1.5/openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
+ { check_lib2 openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
die "ERROR: libopenjpeg not found"; }
enabled libopus && require_pkg_config opus opus_multistream.h opus_multistream_decoder_create
enabled libpulse && require_pkg_config libpulse pulse/pulseaudio.h pa_context_new
@@ -5990,6 +5995,7 @@ __declspec($_restrict) void* foo(int);
EOF
fi
check_func strtoll || add_cflags -Dstrtoll=_strtoi64
+ check_func strtoull || add_cflags -Dstrtoull=_strtoui64
fi
for pfx in "" host_; do
@@ -6406,7 +6412,7 @@ cat > $TMPH <<EOF
#define FFMPEG_CONFIG_H
#define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)"
#define FFMPEG_LICENSE "$(c_escape $license)"
-#define CONFIG_THIS_YEAR 2016
+#define CONFIG_THIS_YEAR 2017
#define FFMPEG_DATADIR "$(eval c_escape $datadir)"
#define AVCONV_DATADIR "$(eval c_escape $datadir)"
#define CC_IDENT "$(c_escape ${cc_ident:-Unknown compiler})"
diff --git a/doc/Doxyfile b/doc/Doxyfile
index 11596536a4..205549c748 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -31,7 +31,7 @@ PROJECT_NAME = FFmpeg
# This could be handy for archiving the generated documentation or
# if some version control system is used.
-PROJECT_NUMBER = 3.0.4
+PROJECT_NUMBER = 3.0.8
# With the PROJECT_LOGO tag one can specify a logo or icon that is included
# in the documentation. The maximum height of the logo should not exceed 55
diff --git a/doc/developer.texi b/doc/developer.texi
index 4d3a7aef94..acb9dc83a2 100644
--- a/doc/developer.texi
+++ b/doc/developer.texi
@@ -131,6 +131,11 @@ designated struct initializers (@samp{struct s x = @{ .i = 17 @};});
@item
compound literals (@samp{x = (struct s) @{ 17, 23 @};}).
+
+@item
+Implementation defined behavior for signed integers is assumed to match the
+expected behavior for two's complement. Non representable values in integer
+casts are binary truncated. Shift right of signed values uses sign extension.
@end itemize
These features are supported by all compilers we care about, so we will not
diff --git a/doc/examples/demuxing_decoding.c b/doc/examples/demuxing_decoding.c
index 59e0ccc986..f2050bd6eb 100644
--- a/doc/examples/demuxing_decoding.c
+++ b/doc/examples/demuxing_decoding.c
@@ -93,10 +93,9 @@ static int decode_packet(int *got_frame, int cached)
return -1;
}
- printf("video_frame%s n:%d coded_n:%d pts:%s\n",
+ printf("video_frame%s n:%d coded_n:%d\n",
cached ? "(cached)" : "",
- video_frame_count++, frame->coded_picture_number,
- av_ts2timestr(frame->pts, &video_dec_ctx->time_base));
+ video_frame_count++, frame->coded_picture_number);
/* copy decoded frame to destination buffer:
* this is required since rawvideo expects non aligned data */
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index e02807cb47..2ee81c283e 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -12,7 +12,7 @@
@chapter Synopsis
-ffmpeg [@var{global_options}] @{[@var{input_file_options}] -i @file{input_file}@} ... @{[@var{output_file_options}] @file{output_file}@} ...
+ffmpeg [@var{global_options}] @{[@var{input_file_options}] -i @file{input_url}@} ... @{[@var{output_file_options}] @file{output_url}@} ...
@chapter Description
@c man begin DESCRIPTION
@@ -24,10 +24,10 @@ rates and resize video on the fly with a high quality polyphase filter.
@command{ffmpeg} reads from an arbitrary number of input "files" (which can be regular
files, pipes, network streams, grabbing devices, etc.), specified by the
@code{-i} option, and writes to an arbitrary number of output "files", which are
-specified by a plain output filename. Anything found on the command line which
-cannot be interpreted as an option is considered to be an output filename.
+specified by a plain output url. Anything found on the command line which
+cannot be interpreted as an option is considered to be an output url.
-Each input or output file can, in principle, contain any number of streams of
+Each input or output url can, in principle, contain any number of streams of
different types (video/audio/subtitle/attachment/data). The allowed number and/or
types of streams may be limited by the container format. Selecting which
streams from which inputs will go into which output is either done automatically
@@ -243,8 +243,8 @@ Force input or output file format. The format is normally auto detected for inpu
files and guessed from the file extension for output files, so this option is not
needed in most cases.
-@item -i @var{filename} (@emph{input})
-input file name
+@item -i @var{url} (@emph{input})
+input file url
@item -y (@emph{global})
Overwrite output files without asking.
@@ -281,7 +281,7 @@ libx264, and the 138th audio, which will be encoded with libvorbis.
When used as an input option (before @code{-i}), limit the @var{duration} of
data read from the input file.
-When used as an output option (before an output filename), stop writing the
+When used as an output option (before an output url), stop writing the
output after its duration reaches @var{duration}.
@var{duration} must be a time duration specification,
@@ -310,7 +310,7 @@ extra segment between the seek point and @var{position} will be decoded and
discarded. When doing stream copy or when @option{-noaccurate_seek} is used, it
will be preserved.
-When used as an output option (before an output filename), decodes but discards
+When used as an output option (before an output url), decodes but discards
input until the timestamps reach @var{position}.
@var{position} must be a time duration specification,
@@ -1129,7 +1129,7 @@ may be reassigned to a different value.
For example, to set the stream 0 PID to 33 and the stream 1 PID to 36 for
an output mpegts file:
@example
-ffmpeg -i infile -streamid 0:33 -streamid 1:36 out.ts
+ffmpeg -i inurl -streamid 0:33 -streamid 1:36 out.ts
@end example
@item -bsf[:@var{stream_specifier}] @var{bitstream_filters} (@emph{output,per-stream})
diff --git a/doc/ffplay.texi b/doc/ffplay.texi
index 4bc3ced39a..073b457256 100644
--- a/doc/ffplay.texi
+++ b/doc/ffplay.texi
@@ -12,7 +12,7 @@
@chapter Synopsis
-ffplay [@var{options}] [@file{input_file}]
+ffplay [@var{options}] [@file{input_url}]
@chapter Description
@c man begin DESCRIPTION
@@ -106,8 +106,8 @@ the input audio.
Use the option "-filters" to show all the available filters (including
sources and sinks).
-@item -i @var{input_file}
-Read @var{input_file}.
+@item -i @var{input_url}
+Read @var{input_url}.
@end table
@section Advanced options
diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
index 2024eed4e5..26530a9962 100644
--- a/doc/ffprobe.texi
+++ b/doc/ffprobe.texi
@@ -12,7 +12,7 @@
@chapter Synopsis
-ffprobe [@var{options}] [@file{input_file}]
+ffprobe [@var{options}] [@file{input_url}]
@chapter Description
@c man begin DESCRIPTION
@@ -24,8 +24,8 @@ For example it can be used to check the format of the container used
by a multimedia stream and the format and type of each media stream
contained in it.
-If a filename is specified in input, ffprobe will try to open and
-probe the file content. If the file cannot be opened or recognized as
+If a url is specified in input, ffprobe will try to open and
+probe the url content. If the url cannot be opened or recognized as
a multimedia file, a positive exit code is returned.
ffprobe may be employed both as a standalone application or in
@@ -332,8 +332,8 @@ with name "PIXEL_FORMAT".
Force bitexact output, useful to produce output which is not dependent
on the specific build.
-@item -i @var{input_file}
-Read @var{input_file}.
+@item -i @var{input_url}
+Read @var{input_url}.
@end table
@c man end
diff --git a/doc/formats.texi b/doc/formats.texi
index 617cda54a9..b62ca43dd7 100644
--- a/doc/formats.texi
+++ b/doc/formats.texi
@@ -205,6 +205,10 @@ For example to separate the fields with newlines and indention:
ffprobe -dump_separator "
" -i ~/videos/matrixbench_mpeg2.mpg
@end example
+
+@item max_streams @var{integer} (@emph{input})
+Specifies the maximum number of streams. This can be used to reject files that
+would require too many resources due to a large number of streams.
@end table
@c man end FORMAT OPTIONS
diff --git a/ffmpeg.c b/ffmpeg.c
index 435ad5730c..4d1a9724bf 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2014,12 +2014,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
}
}
- /* if the decoder provides a pts, use it instead of the last packet pts.
- the decoder could be delaying output by a packet or more. */
- if (decoded_frame->pts != AV_NOPTS_VALUE) {
- ist->dts = ist->next_dts = ist->pts = ist->next_pts = av_rescale_q(decoded_frame->pts, avctx->time_base, AV_TIME_BASE_Q);
- decoded_frame_tb = avctx->time_base;
- } else if (decoded_frame->pkt_pts != AV_NOPTS_VALUE) {
+ if (decoded_frame->pkt_pts != AV_NOPTS_VALUE) {
decoded_frame->pts = decoded_frame->pkt_pts;
decoded_frame_tb = ist->st->time_base;
} else if (pkt->pts != AV_NOPTS_VALUE) {
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index bc8355e2bf..304a4d4d66 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -2989,8 +2989,8 @@ enum OptGroup {
};
static const OptionGroupDef groups[] = {
- [GROUP_OUTFILE] = { "output file", NULL, OPT_OUTPUT },
- [GROUP_INFILE] = { "input file", "i", OPT_INPUT },
+ [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT },
+ [GROUP_INFILE] = { "input url", "i", OPT_INPUT },
};
static int open_files(OptionGroupList *l, const char *inout,
diff --git a/ffserver.c b/ffserver.c
index d73caee9ec..5ce439a0df 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -2701,8 +2701,10 @@ static int http_receive_data(HTTPContext *c)
} else if (c->buffer_ptr - c->buffer >= 2 &&
!memcmp(c->buffer_ptr - 1, "\r\n", 2)) {
c->chunk_size = strtol(c->buffer, 0, 16);
- if (c->chunk_size == 0) // end of stream
+ if (c->chunk_size <= 0) { // end of stream or invalid chunk size
+ c->chunk_size = 0;
goto fail;
+ }
c->buffer_ptr = c->buffer;
break;
} else if (++loop_run > 10)
@@ -2724,6 +2726,7 @@ static int http_receive_data(HTTPContext *c)
/* end of connection : close it */
goto fail;
else {
+ av_assert0(len <= c->chunk_size);
c->chunk_size -= len;
c->buffer_ptr += len;
c->data_count += len;
diff --git a/libavcodec/8bps.c b/libavcodec/8bps.c
index 2e4464dbb4..14f7bd5bf6 100644
--- a/libavcodec/8bps.c
+++ b/libavcodec/8bps.c
@@ -120,12 +120,15 @@ static int decode_frame(AVCodecContext *avctx, void *data,
}
if (avctx->bits_per_coded_sample <= 8) {
+ int size;
const uint8_t *pal = av_packet_get_side_data(avpkt,
AV_PKT_DATA_PALETTE,
- NULL);
- if (pal) {
+ &size);
+ if (pal && size == AVPALETTE_SIZE) {
frame->palette_has_changed = 1;
memcpy(c->pal, pal, AVPALETTE_SIZE);
+ } else if (pal) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
}
memcpy (frame->data[1], c->pal, AVPALETTE_SIZE);
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 26bdea1ecc..708779312c 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -424,6 +424,8 @@ static int read_payload_length_info(struct LATMContext *ctx, GetBitContext *gb)
if (ctx->frame_length_type == 0) {
int mux_slot_length = 0;
do {
+ if (get_bits_left(gb) < 8)
+ return AVERROR_INVALIDDATA;
tmp = get_bits(gb, 8);
mux_slot_length += tmp;
} while (tmp == 255);
@@ -453,7 +455,7 @@ static int read_audio_mux_element(struct LATMContext *latmctx,
}
if (latmctx->audio_mux_version_A == 0) {
int mux_slot_length_bytes = read_payload_length_info(latmctx, gb);
- if (mux_slot_length_bytes * 8 > get_bits_left(gb)) {
+ if (mux_slot_length_bytes < 0 || mux_slot_length_bytes * 8LL > get_bits_left(gb)) {
av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR, "incomplete frame\n");
return AVERROR_INVALIDDATA;
} else if (mux_slot_length_bytes * 8 + 256 < get_bits_left(gb)) {
diff --git a/libavcodec/aacdec_fixed.c b/libavcodec/aacdec_fixed.c
index 396a874d95..bbb120f6fe 100644
--- a/libavcodec/aacdec_fixed.c
+++ b/libavcodec/aacdec_fixed.c
@@ -125,7 +125,7 @@ static inline int *DEC_SQUAD(int *dst, unsigned idx)
static inline int *DEC_UPAIR(int *dst, unsigned idx, unsigned sign)
{
dst[0] = (idx & 15) * (1 - (sign & 0xFFFFFFFE));
- dst[1] = (idx >> 4 & 15) * (1 - ((sign & 1) << 1));
+ dst[1] = (idx >> 4 & 15) * (1 - ((sign & 1) * 2));
return dst + 2;
}
@@ -134,16 +134,16 @@ static inline int *DEC_UQUAD(int *dst, unsigned idx, unsigned sign)
{
unsigned nz = idx >> 12;
- dst[0] = (idx & 3) * (1 + (((int)sign >> 31) << 1));
+ dst[0] = (idx & 3) * (1 + (((int)sign >> 31) * 2));
sign <<= nz & 1;
nz >>= 1;
- dst[1] = (idx >> 2 & 3) * (1 + (((int)sign >> 31) << 1));
+ dst[1] = (idx >> 2 & 3) * (1 + (((int)sign >> 31) * 2));
sign <<= nz & 1;
nz >>= 1;
- dst[2] = (idx >> 4 & 3) * (1 + (((int)sign >> 31) << 1));
+ dst[2] = (idx >> 4 & 3) * (1 + (((int)sign >> 31) * 2));
sign <<= nz & 1;
nz >>= 1;
- dst[3] = (idx >> 6 & 3) * (1 + (((int)sign >> 31) << 1));
+ dst[3] = (idx >> 6 & 3) * (1 + (((int)sign >> 31) * 2));
return dst + 4;
}
@@ -171,7 +171,11 @@ static void subband_scale(int *dst, int *src, int scale, int offset, int len)
s = offset - (s >> 2);
- if (s > 0) {
+ if (s > 31) {
+ for (i=0; i<len; i++) {
+ dst[i] = 0;
+ }
+ } else if (s > 0) {
round = 1 << (s-1);
for (i=0; i<len; i++) {
out = (int)(((int64_t)src[i] * c) >> 32);
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 6bc94c879a..ded9e464a7 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -2155,7 +2155,11 @@ static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che)
coup->coupling_point += get_bits1(gb) || (coup->coupling_point >> 1);
sign = get_bits(gb, 1);
- scale = AAC_RENAME(cce_scale)[get_bits(gb, 2)];
+#if USE_FIXED
+ scale = get_bits(gb, 2);
+#else
+ scale = cce_scale[get_bits(gb, 2)];
+#endif
if ((ret = decode_ics(ac, sce, gb, 0, 0)))
return ret;
diff --git a/libavcodec/aacps.c b/libavcodec/aacps.c
index ccc79ffc1d..48b595adbd 100644
--- a/libavcodec/aacps.c
+++ b/libavcodec/aacps.c
@@ -975,7 +975,7 @@ static void stereo_processing(PSContext *ps, INTFLOAT (*l)[32][2], INTFLOAT (*r)
h_step[1][3] = AAC_MSUB31_V3(H22[1][e+1][b], h[1][3], width);
}
ps->dsp.stereo_interpolate[!PS_BASELINE && ps->enable_ipdopd](
- l[k] + start + 1, r[k] + start + 1,
+ l[k] + 1 + start, r[k] + 1 + start,
h, h_step, stop - start);
}
}
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index 733e619b78..3dcdcd898d 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -623,24 +623,26 @@ static int read_sbr_grid(AACContext *ac, SpectralBandReplication *sbr,
int abs_bord_trail = 16;
int num_rel_lead, num_rel_trail;
unsigned bs_num_env_old = ch_data->bs_num_env;
+ int bs_frame_class, bs_num_env;
ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env];
ch_data->bs_amp_res = sbr->bs_amp_res_header;
ch_data->t_env_num_env_old = ch_data->t_env[bs_num_env_old];
- switch (ch_data->bs_frame_class = get_bits(gb, 2)) {
+ switch (bs_frame_class = get_bits(gb, 2)) {
case FIXFIX:
- ch_data->bs_num_env = 1 << get_bits(gb, 2);
- num_rel_lead = ch_data->bs_num_env - 1;
- if (ch_data->bs_num_env == 1)
- ch_data->bs_amp_res = 0;
-
- if (ch_data->bs_num_env > 4) {
+ bs_num_env = 1 << get_bits(gb, 2);
+ if (bs_num_env > 4) {
av_log(ac->avctx, AV_LOG_ERROR,
"Invalid bitstream, too many SBR envelopes in FIXFIX type SBR frame: %d\n",
- ch_data->bs_num_env);
+ bs_num_env);
return -1;
}
+ ch_data->bs_num_env = bs_num_env;
+ num_rel_lead = ch_data->bs_num_env - 1;
+ if (ch_data->bs_num_env == 1)
+ ch_data->bs_amp_res = 0;
+
ch_data->t_env[0] = 0;
ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
@@ -688,14 +690,15 @@ static int read_sbr_grid(AACContext *ac, SpectralBandReplication *sbr,
abs_bord_trail += get_bits(gb, 2);
num_rel_lead = get_bits(gb, 2);
num_rel_trail = get_bits(gb, 2);
- ch_data->bs_num_env = num_rel_lead + num_rel_trail + 1;
+ bs_num_env = num_rel_lead + num_rel_trail + 1;
- if (ch_data->bs_num_env > 5) {
+ if (bs_num_env > 5) {
av_log(ac->avctx, AV_LOG_ERROR,
"Invalid bitstream, too many SBR envelopes in VARVAR type SBR frame: %d\n",
- ch_data->bs_num_env);
+ bs_num_env);
return -1;
}
+ ch_data->bs_num_env = bs_num_env;
ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
@@ -710,6 +713,7 @@ static int read_sbr_grid(AACContext *ac, SpectralBandReplication *sbr,
get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env);
break;
}
+ ch_data->bs_frame_class = bs_frame_class;
av_assert0(bs_pointer >= 0);
if (bs_pointer > ch_data->bs_num_env + 1) {
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index f82f3974ef..4971abe9f4 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -744,30 +744,31 @@ static void ac3_upmix_delay(AC3DecodeContext *s)
* @param[in] default_band_struct default band structure table
* @param[out] num_bands number of bands (optionally NULL)
* @param[out] band_sizes array containing the number of bins in each band (optionally NULL)
+ * @param[in,out] band_struct current band structure
*/
static void decode_band_structure(GetBitContext *gbc, int blk, int eac3,
int ecpl, int start_subband, int end_subband,
const uint8_t *default_band_struct,
- int *num_bands, uint8_t *band_sizes)
+ int *num_bands, uint8_t *band_sizes,
+ uint8_t *band_struct, int band_struct_size)
{
int subbnd, bnd, n_subbands, n_bands=0;
uint8_t bnd_sz[22];
- uint8_t coded_band_struct[22];
- const uint8_t *band_struct;
n_subbands = end_subband - start_subband;
+ if (!blk)
+ memcpy(band_struct, default_band_struct, band_struct_size);
+
+ av_assert0(band_struct_size >= start_subband + n_subbands);
+
+ band_struct += start_subband + 1;
+
/* decode band structure from bitstream or use default */
if (!eac3 || get_bits1(gbc)) {
for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) {
- coded_band_struct[subbnd] = get_bits1(gbc);
+ band_struct[subbnd] = get_bits1(gbc);
}
- band_struct = coded_band_struct;
- } else if (!blk) {
- band_struct = &default_band_struct[start_subband+1];
- } else {
- /* no change in band structure */
- return;
}
/* calculate number of bands and band sizes based on band structure.
@@ -894,7 +895,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
start_subband, end_subband,
ff_eac3_default_spx_band_struct,
&s->num_spx_bands,
- s->spx_band_sizes);
+ s->spx_band_sizes,
+ s->spx_band_struct, sizeof(s->spx_band_struct));
}
}
if (!s->eac3 || !s->spx_in_use) {
@@ -1028,7 +1030,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
decode_band_structure(gbc, blk, s->eac3, 0, cpl_start_subband,
cpl_end_subband,
ff_eac3_default_cpl_band_struct,
- &s->num_cpl_bands, s->cpl_band_sizes);
+ &s->num_cpl_bands, s->cpl_band_sizes,
+ s->cpl_band_struct, sizeof(s->cpl_band_struct));
} else {
/* coupling not in use */
for (ch = 1; ch <= fbw_channels; ch++) {
@@ -1328,7 +1331,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
for (ch = 1; ch <= s->channels; ch++) {
int audio_channel = 0;
INTFLOAT gain;
- if (s->channel_mode == AC3_CHMODE_DUALMONO)
+ if (s->channel_mode == AC3_CHMODE_DUALMONO && ch <= 2)
audio_channel = 2-ch;
if (s->heavy_compression && s->compression_exists[audio_channel])
gain = s->heavy_dynamic_range[audio_channel];
diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h
index b3498fec96..fe3cf86c43 100644
--- a/libavcodec/ac3dec.h
+++ b/libavcodec/ac3dec.h
@@ -126,6 +126,7 @@ typedef struct AC3DecodeContext {
int phase_flags_in_use; ///< phase flags in use (phsflginu)
int phase_flags[AC3_MAX_CPL_BANDS]; ///< phase flags (phsflg)
int num_cpl_bands; ///< number of coupling bands (ncplbnd)
+ uint8_t cpl_band_struct[AC3_MAX_CPL_BANDS];
uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS]; ///< number of coeffs in each coupling band
int firstchincpl; ///< first channel in coupling
int first_cpl_coords[AC3_MAX_CHANNELS]; ///< first coupling coordinates states (firstcplcos)
@@ -142,6 +143,7 @@ typedef struct AC3DecodeContext {
int spx_dst_start_freq; ///< spx starting frequency bin for copying (copystartmant)
///< the copy region ends at the start of the spx region.
int num_spx_bands; ///< number of spx bands (nspxbnds)
+ uint8_t spx_band_struct[SPX_MAX_BANDS];
uint8_t spx_band_sizes[SPX_MAX_BANDS]; ///< number of bins in each spx band
uint8_t first_spx_coords[AC3_MAX_CHANNELS]; ///< first spx coordinates states (firstspxcos)
INTFLOAT spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]; ///< spx noise blending factor (nblendfact)
diff --git a/libavcodec/adxdec.c b/libavcodec/adxdec.c
index 32cc0f005a..178ea99dcf 100644
--- a/libavcodec/adxdec.c
+++ b/libavcodec/adxdec.c
@@ -81,7 +81,7 @@ static int adx_decode(ADXContext *c, int16_t *out, int offset,
s2 = prev->s2;
for (i = 0; i < BLOCK_SAMPLES; i++) {
d = get_sbits(&gb, 4);
- s0 = ((d << COEFF_BITS) * scale + c->coeff[0] * s1 + c->coeff[1] * s2) >> COEFF_BITS;
+ s0 = ((d * (1 << COEFF_BITS)) * scale + c->coeff[0] * s1 + c->coeff[1] * s2) >> COEFF_BITS;
s2 = s1;
s1 = av_clip_int16(s0);
*out++ = s1;
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index a99dbd110e..1431870fa3 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -265,7 +265,7 @@ static void decode_pitch_lag_high(int *lag_int, int *lag_frac, int pitch_index,
*lag_frac = pitch_index - (*lag_int << 2) + 136;
} else if (pitch_index < 440) {
*lag_int = (pitch_index + 257 - 376) >> 1;
- *lag_frac = (pitch_index - (*lag_int << 1) + 256 - 376) << 1;
+ *lag_frac = (pitch_index - (*lag_int << 1) + 256 - 376) * 2;
/* the actual resolution is 1/2 but expressed as 1/4 */
} else {
*lag_int = pitch_index - 280;
@@ -295,7 +295,7 @@ static void decode_pitch_lag_low(int *lag_int, int *lag_frac, int pitch_index,
if (subframe == 0 || (subframe == 2 && mode != MODE_6k60)) {
if (pitch_index < 116) {
*lag_int = (pitch_index + 69) >> 1;
- *lag_frac = (pitch_index - (*lag_int << 1) + 68) << 1;
+ *lag_frac = (pitch_index - (*lag_int << 1) + 68) * 2;
} else {
*lag_int = pitch_index - 24;
*lag_frac = 0;
@@ -305,7 +305,7 @@ static void decode_pitch_lag_low(int *lag_int, int *lag_frac, int pitch_index,
AMRWB_P_DELAY_MIN, AMRWB_P_DELAY_MAX - 15);
} else {
*lag_int = (pitch_index + 1) >> 1;
- *lag_frac = (pitch_index - (*lag_int << 1)) << 1;
+ *lag_frac = (pitch_index - (*lag_int << 1)) * 2;
*lag_int += *base_lag_int;
}
}
diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c
index ec98a0ce35..c4eca2a13d 100644
--- a/libavcodec/asvenc.c
+++ b/libavcodec/asvenc.c
@@ -61,7 +61,7 @@ static inline void asv2_put_level(ASV1Context *a, PutBitContext *pb, int level)
} else {
put_bits(pb, ff_asv2_level_tab[31][1], ff_asv2_level_tab[31][0]);
if (level < -128 || level > 127) {
- av_log(a->avctx, AV_LOG_WARNING, "Cliping level %d, increase qscale\n", level);
+ av_log(a->avctx, AV_LOG_WARNING, "Clipping level %d, increase qscale\n", level);
level = av_clip_int8(level);
}
asv2_put_bits(pb, 8, level & 0xFF);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d8497655b0..54c7e49c59 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1403,6 +1403,16 @@ enum AVPacketSideDataType {
* side data includes updated metadata which appeared in the stream.
*/
AV_PKT_DATA_METADATA_UPDATE,
+
+ /**
+ * The number of side data elements (in fact a bit more than it).
+ * This is not part of the public API/ABI in the sense that it may
+ * change when new side data types are added.
+ * This must stay the last enum value.
+ * If its value becomes huge, some code using it
+ * needs to be updated as it assumes it to be smaller than other limits.
+ */
+ AV_PKT_DATA_NB
};
#define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 6de85dea1d..5e2e969659 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -280,16 +280,17 @@ FF_ENABLE_DEPRECATION_WARNINGS
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
uint8_t *data, size_t size)
{
+ AVPacketSideData *tmp;
int elems = pkt->side_data_elems;
- if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data))
+ if ((unsigned)elems + 1 > AV_PKT_DATA_NB)
return AVERROR(ERANGE);
- pkt->side_data = av_realloc(pkt->side_data,
- (elems + 1) * sizeof(*pkt->side_data));
- if (!pkt->side_data)
+ tmp = av_realloc(pkt->side_data, (elems + 1) * sizeof(*tmp));
+ if (!tmp)
return AVERROR(ENOMEM);
+ pkt->side_data = tmp;
pkt->side_data[elems].data = data;
pkt->side_data[elems].size = size;
pkt->side_data[elems].type = type;
@@ -332,6 +333,8 @@ uint8_t *av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
return pkt->side_data[i].data;
}
}
+ if (size)
+ *size = 0;
return NULL;
}
@@ -413,6 +416,9 @@ int av_packet_split_side_data(AVPacket *pkt){
p-= size+5;
}
+ if (i > AV_PKT_DATA_NB)
+ return AVERROR(ERANGE);
+
pkt->side_data = av_malloc_array(i, sizeof(*pkt->side_data));
if (!pkt->side_data)
return AVERROR(ENOMEM);
diff --git a/libavcodec/bmvvideo.c b/libavcodec/bmvvideo.c
index 97f850dbae..cf7f0a0501 100644
--- a/libavcodec/bmvvideo.c
+++ b/libavcodec/bmvvideo.c
@@ -107,7 +107,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame,
if (src < source || src >= source_end)
return AVERROR_INVALIDDATA;
shift += 2;
- val |= *src << shift;
+ val |= (unsigned)*src << shift;
if (*src & 0xC)
break;
}
diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c
index 10a25d8749..0bbf975a80 100644
--- a/libavcodec/cavs.c
+++ b/libavcodec/cavs.c
@@ -614,8 +614,15 @@ void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
mv_pred_median(h, mvP, mvA, mvB, mvC);
if (mode < MV_PRED_PSKIP) {
- mvP->x += get_se_golomb(&h->gb);
- mvP->y += get_se_golomb(&h->gb);
+ int mx = get_se_golomb(&h->gb) + (unsigned)mvP->x;
+ int my = get_se_golomb(&h->gb) + (unsigned)mvP->y;
+
+ if (mx != (int16_t)mx || my != (int16_t)my) {
+ av_log(h->avctx, AV_LOG_ERROR, "MV %d %d out of supported range\n", mx, my);
+ } else {
+ mvP->x = mx;
+ mvP->y = my;
+ }
}
set_mvs(mvP, size);
}
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index 70ac6f8a42..4d1b77187b 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -465,7 +465,7 @@ static inline void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw,
cavs_vector *col_mv)
{
cavs_vector *pmv_bw = pmv_fw + MV_BWD_OFFS;
- int den = h->direct_den[col_mv->ref];
+ unsigned den = h->direct_den[col_mv->ref];
int m = FF_SIGNBIT(col_mv->x);
pmv_fw->dist = h->dist[1];
@@ -1031,6 +1031,10 @@ static int decode_pic(AVSContext *h)
h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0;
if (h->cur.f->pict_type == AV_PICTURE_TYPE_B) {
h->sym_factor = h->dist[0] * h->scale_den[1];
+ if (FFABS(h->sym_factor) > 32768) {
+ av_log(h->avctx, AV_LOG_ERROR, "sym_factor %d too large\n", h->sym_factor);
+ return AVERROR_INVALIDDATA;
+ }
} else {
h->direct_den[0] = h->dist[0] ? 16384 / h->dist[0] : 0;
h->direct_den[1] = h->dist[1] ? 16384 / h->dist[1] : 0;
@@ -1217,6 +1221,8 @@ static int cavs_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
h->got_keyframe = 1;
}
case PIC_PB_START_CODE:
+ if (*got_frame)
+ av_frame_unref(data);
*got_frame = 0;
if (!h->got_keyframe)
break;
diff --git a/libavcodec/cdxl.c b/libavcodec/cdxl.c
index 50d514b25d..3eaf194d2f 100644
--- a/libavcodec/cdxl.c
+++ b/libavcodec/cdxl.c
@@ -252,11 +252,11 @@ static int cdxl_decode_frame(AVCodecContext *avctx, void *data,
aligned_width = FFALIGN(c->avctx->width, 16);
c->padded_bits = aligned_width - c->avctx->width;
- if (c->video_size < aligned_width * avctx->height * c->bpp / 8)
+ if (c->video_size < aligned_width * avctx->height * (int64_t)c->bpp / 8)
return AVERROR_INVALIDDATA;
- if (!encoding && c->palette_size && c->bpp <= 8) {
+ if (!encoding && c->palette_size && c->bpp <= 8 && c->format != CHUNKY) {
avctx->pix_fmt = AV_PIX_FMT_PAL8;
- } else if (encoding == 1 && (c->bpp == 6 || c->bpp == 8)) {
+ } else if (encoding == 1 && (c->bpp == 6 || c->bpp == 8) && c->format != CHUNKY) {
if (c->palette_size != (1 << (c->bpp - 1)))
return AVERROR_INVALIDDATA;
avctx->pix_fmt = AV_PIX_FMT_BGR24;
diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c
index f1a4656303..58c26dc69c 100644
--- a/libavcodec/cinepak.c
+++ b/libavcodec/cinepak.c
@@ -443,10 +443,13 @@ static int cinepak_decode_frame(AVCodecContext *avctx,
return ret;
if (s->palette_video) {
- const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
- if (pal) {
+ int size;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size);
+ if (pal && size == AVPALETTE_SIZE) {
s->frame->palette_has_changed = 1;
memcpy(s->pal, pal, AVPALETTE_SIZE);
+ } else if (pal) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
}
}
diff --git a/libavcodec/cllc.c b/libavcodec/cllc.c
index 1c6902afd4..97d3ae40ea 100644
--- a/libavcodec/cllc.c
+++ b/libavcodec/cllc.c
@@ -29,6 +29,10 @@
#include "avcodec.h"
#include "internal.h"
+#define VLC_BITS 7
+#define VLC_DEPTH 2
+
+
typedef struct CLLCContext {
AVCodecContext *avctx;
BswapDSPContext bdsp;
@@ -51,6 +55,13 @@ static int read_code_table(CLLCContext *ctx, GetBitContext *gb, VLC *vlc)
num_lens = get_bits(gb, 5);
+ if (num_lens > VLC_BITS * VLC_DEPTH) {
+ vlc->table = NULL;
+
+ av_log(ctx->avctx, AV_LOG_ERROR, "To long VLCs %d\n", num_lens);
+ return AVERROR_INVALIDDATA;
+ }
+
for (i = 0; i < num_lens; i++) {
num_codes = get_bits(gb, 9);
num_codes_sum += num_codes;
@@ -70,11 +81,15 @@ static int read_code_table(CLLCContext *ctx, GetBitContext *gb, VLC *vlc)
count++;
}
+ if (prefix > (65535 - 256)/2) {
+ vlc->table = NULL;
+ return AVERROR_INVALIDDATA;
+ }
prefix <<= 1;
}
- return ff_init_vlc_sparse(vlc, 7, count, bits, 1, 1,
+ return ff_init_vlc_sparse(vlc, VLC_BITS, count, bits, 1, 1,
codes, 2, 2, symbols, 1, 1, 0);
}
@@ -101,7 +116,7 @@ static int read_argb_line(CLLCContext *ctx, GetBitContext *gb, int *top_left,
for (i = 0; i < ctx->avctx->width; i++) {
/* Always get the alpha component */
UPDATE_CACHE(bits, gb);
- GET_VLC(code, bits, gb, vlc[0].table, 7, 2);
+ GET_VLC(code, bits, gb, vlc[0].table, VLC_BITS, VLC_DEPTH);
pred[0] += code;
dst[0] = pred[0];
@@ -110,21 +125,21 @@ static int read_argb_line(CLLCContext *ctx, GetBitContext *gb, int *top_left,
if (dst[0]) {
/* Red */
UPDATE_CACHE(bits, gb);
- GET_VLC(code, bits, gb, vlc[1].table, 7, 2);
+ GET_VLC(code, bits, gb, vlc[1].table, VLC_BITS, VLC_DEPTH);
pred[1] += code;
dst[1] = pred[1];
/* Green */
UPDATE_CACHE(bits, gb);
- GET_VLC(code, bits, gb, vlc[2].table, 7, 2);
+ GET_VLC(code, bits, gb, vlc[2].table, VLC_BITS, VLC_DEPTH);
pred[2] += code;
dst[2] = pred[2];
/* Blue */
UPDATE_CACHE(bits, gb);
- GET_VLC(code, bits, gb, vlc[3].table, 7, 2);
+ GET_VLC(code, bits, gb, vlc[3].table, VLC_BITS, VLC_DEPTH);
pred[3] += code;
dst[3] = pred[3];
@@ -166,7 +181,7 @@ static int read_rgb24_component_line(CLLCContext *ctx, GetBitContext *gb,
/* Simultaneously read and restore the line */
for (i = 0; i < ctx->avctx->width; i++) {
UPDATE_CACHE(bits, gb);
- GET_VLC(code, bits, gb, vlc->table, 7, 2);
+ GET_VLC(code, bits, gb, vlc->table, VLC_BITS, VLC_DEPTH);
pred += code;
dst[0] = pred;
@@ -195,7 +210,7 @@ static int read_yuv_component_line(CLLCContext *ctx, GetBitContext *gb,
/* Simultaneously read and restore the line */
for (i = 0; i < ctx->avctx->width >> is_chroma; i++) {
UPDATE_CACHE(bits, gb);
- GET_VLC(code, bits, gb, vlc->table, 7, 2);
+ GET_VLC(code, bits, gb, vlc->table, VLC_BITS, VLC_DEPTH);
pred += code;
outbuf[i] = pred;
diff --git a/libavcodec/dcadsp.c b/libavcodec/dcadsp.c
index 09faee51fb..4316a2eb98 100644
--- a/libavcodec/dcadsp.c
+++ b/libavcodec/dcadsp.c
@@ -320,7 +320,7 @@ static void dmix_sub_c(int32_t *dst, const int32_t *src, int coeff, ptrdiff_t le
int i;
for (i = 0; i < len; i++)
- dst[i] -= mul15(src[i], coeff);
+ dst[i] -= (unsigned)mul15(src[i], coeff);
}
static void dmix_add_c(int32_t *dst, const int32_t *src, int coeff, ptrdiff_t len)
diff --git a/libavcodec/dds.c b/libavcodec/dds.c
index 9577b67f0f..7cb89dade7 100644
--- a/libavcodec/dds.c
+++ b/libavcodec/dds.c
@@ -39,7 +39,7 @@
#define DDPF_FOURCC (1 << 2)
#define DDPF_PALETTE (1 << 5)
-#define DDPF_NORMALMAP (1 << 31)
+#define DDPF_NORMALMAP (1U << 31)
enum DDSPostProc {
DDS_NONE = 0,
@@ -676,7 +676,7 @@ static int dds_decode(AVCodecContext *avctx, void *data,
(frame->data[1][2+i*4]<<0)+
(frame->data[1][1+i*4]<<8)+
(frame->data[1][0+i*4]<<16)+
- (frame->data[1][3+i*4]<<24)
+ ((unsigned)frame->data[1][3+i*4]<<24)
);
frame->palette_has_changed = 1;
diff --git a/libavcodec/dfa.c b/libavcodec/dfa.c
index f45d019a79..8067ac94e5 100644
--- a/libavcodec/dfa.c
+++ b/libavcodec/dfa.c
@@ -67,7 +67,8 @@ static int decode_tsw1(GetByteContext *gb, uint8_t *frame, int width, int height
const uint8_t *frame_start = frame;
const uint8_t *frame_end = frame + width * height;
int mask = 0x10000, bitbuf = 0;
- int v, count, segments;
+ int v, count;
+ unsigned segments;
unsigned offset;
segments = bytestream2_get_le32(gb);
@@ -175,7 +176,7 @@ static int decode_dds1(GetByteContext *gb, uint8_t *frame, int width, int height
return AVERROR_INVALIDDATA;
frame += v;
} else {
- if (frame_end - frame < width + 3)
+ if (frame_end - frame < width + 4)
return AVERROR_INVALIDDATA;
frame[0] = frame[1] =
frame[width] = frame[width + 1] = bytestream2_get_byte(gb);
@@ -249,7 +250,7 @@ static int decode_wdlt(GetByteContext *gb, uint8_t *frame, int width, int height
segments = bytestream2_get_le16u(gb);
while ((segments & 0xC000) == 0xC000) {
unsigned skip_lines = -(int16_t)segments;
- unsigned delta = -((int16_t)segments * width);
+ int64_t delta = -((int16_t)segments * (int64_t)width);
if (frame_end - frame <= delta || y + lines + skip_lines > height)
return AVERROR_INVALIDDATA;
frame += delta;
diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c
index 1242bd821d..05249f3157 100644
--- a/libavcodec/diracdec.c
+++ b/libavcodec/diracdec.c
@@ -1900,7 +1900,9 @@ static int dirac_decode_picture_header(DiracContext *s)
for (j = 0; j < MAX_FRAMES; j++)
if (!s->all_frames[j].avframe->data[0]) {
s->ref_pics[i] = &s->all_frames[j];
- get_buffer_with_edge(s->avctx, s->ref_pics[i]->avframe, AV_GET_BUFFER_FLAG_REF);
+ ret = get_buffer_with_edge(s->avctx, s->ref_pics[i]->avframe, AV_GET_BUFFER_FLAG_REF);
+ if (ret < 0)
+ return ret;
break;
}
@@ -1964,9 +1966,9 @@ static int get_delayed_pic(DiracContext *s, AVFrame *picture, int *got_frame)
if (out) {
out->reference ^= DELAYED_PIC_REF;
- *got_frame = 1;
if((ret = av_frame_ref(picture, out->avframe)) < 0)
return ret;
+ *got_frame = 1;
}
return 0;
diff --git a/libavcodec/dss_sp.c b/libavcodec/dss_sp.c
index 7cf84899fc..f5dfda3642 100644
--- a/libavcodec/dss_sp.c
+++ b/libavcodec/dss_sp.c
@@ -33,7 +33,7 @@
#define DSS_SP_FRAME_SIZE 42
#define DSS_SP_SAMPLE_COUNT (66 * SUBFRAMES)
-#define DSS_SP_FORMULA(a, b, c) (((((a) << 15) + (b) * (c)) + 0x4000) >> 15)
+#define DSS_SP_FORMULA(a, b, c) ((int)((((a) * (1 << 15)) + (b) * (unsigned)(c)) + 0x4000) >> 15)
typedef struct DssSpSubframe {
int16_t gain;
@@ -499,7 +499,7 @@ static void dss_sp_scale_vector(int32_t *vec, int bits, int size)
vec[i] = vec[i] >> -bits;
else
for (i = 0; i < size; i++)
- vec[i] = vec[i] << bits;
+ vec[i] = vec[i] * (1 << bits);
}
static void dss_sp_update_buf(int32_t *hist, int32_t *vector)
@@ -524,12 +524,12 @@ static void dss_sp_shift_sq_sub(const int32_t *filter_buf,
tmp = dst[a] * filter_buf[0];
for (i = 14; i > 0; i--)
- tmp -= error_buf[i] * filter_buf[i];
+ tmp -= error_buf[i] * (unsigned)filter_buf[i];
for (i = 14; i > 0; i--)
error_buf[i] = error_buf[i - 1];
- tmp = (tmp + 4096) >> 13;
+ tmp = (int)(tmp + 4096U) >> 13;
error_buf[1] = tmp;
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index a4663d997f..7c9ae999c2 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -24,6 +24,7 @@
#include "bytestream.h"
#include "internal.h"
#include "libavutil/colorspace.h"
+#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#define DVBSUB_PAGE_SEGMENT 0x10
@@ -810,7 +811,7 @@ static void compute_default_clut(AVSubtitleRect *rect, int w, int h)
list_inv[ i ] = bestv;
}
- count = i - 1;
+ count = FFMAX(i - 1, 1);
for (i--; i>=0; i--) {
int v = i*255/count;
AV_WN32(rect->data[1] + 4*list_inv[i], RGBA(v/2,v,v/2,v));
@@ -1214,9 +1215,9 @@ static int dvbsub_parse_clut_segment(AVCodecContext *avctx,
return AVERROR_INVALIDDATA;
}
- if (depth & 0x80)
+ if (depth & 0x80 && entry_id < 4)
clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);
- else if (depth & 0x40)
+ else if (depth & 0x40 && entry_id < 16)
clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);
else if (depth & 0x20)
clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
@@ -1239,6 +1240,7 @@ static int dvbsub_parse_region_segment(AVCodecContext *avctx,
DVBSubObject *object;
DVBSubObjectDisplay *display;
int fill;
+ int ret;
if (buf_size < 10)
return AVERROR_INVALIDDATA;
@@ -1267,6 +1269,12 @@ static int dvbsub_parse_region_segment(AVCodecContext *avctx,
region->height = AV_RB16(buf);
buf += 2;
+ ret = av_image_check_size(region->width, region->height, 0, avctx);
+ if (ret < 0) {
+ region->width= region->height= 0;
+ return ret;
+ }
+
if (region->width * region->height != region->buf_size) {
av_free(region->pbuf);
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 19f25f0e60..917adc3dfe 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -60,7 +60,7 @@ static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *
cb = *ycbcr++;
YUV_TO_RGB1_CCIR(cb, cr);
YUV_TO_RGB2_CCIR(r, g, b, y);
- *rgba++ = (*alpha++ << 24) | (r << 16) | (g << 8) | b;
+ *rgba++ = ((unsigned)*alpha++ << 24) | (r << 16) | (g << 8) | b;
}
}
@@ -185,16 +185,16 @@ static void guess_palette(DVDSubContext* ctx,
for(i = 0; i < 4; i++) {
if (alpha[i] != 0) {
if (!color_used[colormap[i]]) {
- level = level_map[nb_opaque_colors][j];
+ level = level_map[nb_opaque_colors - 1][j];
r = (((subtitle_color >> 16) & 0xff) * level) >> 8;
g = (((subtitle_color >> 8) & 0xff) * level) >> 8;
b = (((subtitle_color >> 0) & 0xff) * level) >> 8;
- rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24);
+ rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17U) << 24);
color_used[colormap[i]] = (i + 1);
j++;
} else {
rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) |
- ((alpha[i] * 17) << 24);
+ ((alpha[i] * 17U) << 24);
}
}
}
@@ -548,7 +548,8 @@ static int append_to_cached_buf(AVCodecContext *avctx,
{
DVDSubContext *ctx = avctx->priv_data;
- if (ctx->buf_size >= sizeof(ctx->buf) - buf_size) {
+ av_assert0(buf_size >= 0 && ctx->buf_size <= sizeof(ctx->buf));
+ if (buf_size >= sizeof(ctx->buf) - ctx->buf_size) {
av_log(avctx, AV_LOG_WARNING, "Attempt to reconstruct "
"too large SPU packets aborted.\n");
ctx->buf_size = 0;
diff --git a/libavcodec/eac3dec.c b/libavcodec/eac3dec.c
index ef815afb55..001a404389 100644
--- a/libavcodec/eac3dec.c
+++ b/libavcodec/eac3dec.c
@@ -252,7 +252,7 @@ static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
/* Vector Quantization */
int v = get_bits(gbc, bits);
for (blk = 0; blk < 6; blk++) {
- s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8;
+ s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
}
} else {
/* Gain Adaptive Quantization */
@@ -271,16 +271,16 @@ static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
int b;
int mbits = bits - (2 - log_gain);
mant = get_sbits(gbc, mbits);
- mant <<= (23 - (mbits - 1));
+ mant = ((unsigned)mant) << (23 - (mbits - 1));
/* remap mantissa value to correct for asymmetric quantization */
if (mant >= 0)
b = 1 << (23 - log_gain);
else
- b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] << 8;
+ b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
} else {
/* small mantissa, no GAQ, or Gk=1 */
- mant <<= 24 - bits;
+ mant *= (1 << 24 - bits);
if (!log_gain) {
/* remap mantissa value for no GAQ or Gk=1 */
mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c
index 4e202f98a3..0525394838 100644
--- a/libavcodec/eamad.c
+++ b/libavcodec/eamad.c
@@ -284,7 +284,7 @@ static int decode_frame(AVCodecContext *avctx,
if (avctx->width != width || avctx->height != height) {
av_frame_unref(s->last_frame);
- if((width * height)/2048*7 > bytestream2_get_bytes_left(&gb))
+ if((width * (int64_t)height)/2048*7 > bytestream2_get_bytes_left(&gb))
return AVERROR_INVALIDDATA;
if ((ret = ff_set_dimensions(avctx, width, height)) < 0)
return ret;
diff --git a/libavcodec/eatqi.c b/libavcodec/eatqi.c
index 2423e21a41..75f914cd2f 100644
--- a/libavcodec/eatqi.c
+++ b/libavcodec/eatqi.c
@@ -93,7 +93,7 @@ static inline void tqi_idct_put(TqiContext *t, AVFrame *frame, int16_t (*block)[
static void tqi_calculate_qtable(MpegEncContext *s, int quant)
{
- const int qscale = (215 - 2*quant)*5;
+ const int64_t qscale = (215 - 2*quant)*5;
int i;
s->intra_matrix[0] = (ff_inv_aanscales[0]*ff_mpeg1_default_intra_matrix[0])>>11;
for(i=1; i<64; i++)
diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c
index 50a86c8355..dfbaec9877 100644
--- a/libavcodec/escape124.c
+++ b/libavcodec/escape124.c
@@ -250,6 +250,10 @@ static int escape124_decode_frame(AVCodecContext *avctx,
// This codebook can be cut off at places other than
// powers of 2, leaving some of the entries undefined.
cb_size = get_bits_long(&gb, 20);
+ if (!cb_size) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid codebook size 0.\n");
+ return AVERROR_INVALIDDATA;
+ }
cb_depth = av_log2(cb_size - 1) + 1;
} else {
cb_depth = get_bits(&gb, 4);
diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 9ec99d65a0..292707cd0a 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -186,9 +186,9 @@ static union av_intfloat32 exr_half2float(uint16_t hf)
*
* @return normalized 16-bit unsigned int
*/
-static inline uint16_t exr_flt2uint(uint32_t v)
+static inline uint16_t exr_flt2uint(int32_t v)
{
- unsigned int exp = v >> 23;
+ int32_t exp = v >> 23;
// "HACK": negative values result in exp< 0, so clipping them to 0
// is also handled by this condition, avoids explicit check for sign bit.
if (exp <= 127 + 7 - 24) // we would shift out all bits anyway
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index d2bf3a89fd..5f7e11fc33 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -45,7 +45,8 @@ static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state,
if (get_rac(c, state + 0))
return 0;
else {
- int i, e, a;
+ int i, e;
+ unsigned a;
e = 0;
while (get_rac(c, state + 1 + FFMIN(e, 9))) { // 1..10
e++;
@@ -1002,7 +1003,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
const uint8_t *src[4];
uint8_t *dst[4];
ff_thread_await_progress(&f->last_picture, INT_MAX, 0);
- for (j = 0; j < 4; j++) {
+ for (j = 0; j < desc->nb_components; j++) {
int pixshift = desc->comp[j].depth > 8;
int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0;
int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0;
@@ -1010,6 +1011,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
(fs->slice_y >> sv) + ((fs->slice_x >> sh) << pixshift);
src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j] *
(fs->slice_y >> sv) + ((fs->slice_x >> sh) << pixshift);
+
+ }
+ if (desc->flags & AV_PIX_FMT_FLAG_PAL ||
+ desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
+ dst[1] = p->data[1];
+ src[1] = f->last_picture.f->data[1];
}
av_image_copy(dst, p->linesize, src,
f->last_picture.f->linesize,
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 42e59a1efc..9b14309b31 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1222,7 +1222,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
FFV1Context *f = avctx->priv_data;
RangeCoder *const c = &f->slice_context[0]->c;
AVFrame *const p = f->picture.f;
- int used_count = 0;
uint8_t keystate = 128;
uint8_t *buf_p;
int i, ret;
@@ -1278,6 +1277,11 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
if (f->version > 3)
maxsize = AV_INPUT_BUFFER_MIN_SIZE + avctx->width*avctx->height*3LL*4;
+ if (maxsize > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32) {
+ av_log(avctx, AV_LOG_WARNING, "Cannot allocate worst case packet size, the encoding could fail\n");
+ maxsize = INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32;
+ }
+
if ((ret = ff_alloc_packet2(avctx, pkt, maxsize, 0)) < 0)
return ret;
@@ -1307,11 +1311,17 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}
}
- for (i = 1; i < f->slice_count; i++) {
+ for (i = 0; i < f->slice_count; i++) {
FFV1Context *fs = f->slice_context[i];
- uint8_t *start = pkt->data + (pkt->size - used_count) * (int64_t)i / f->slice_count;
+ uint8_t *start = pkt->data + pkt->size * (int64_t)i / f->slice_count;
int len = pkt->size / f->slice_count;
- ff_init_range_encoder(&fs->c, start, len);
+ if (i) {
+ ff_init_range_encoder(&fs->c, start, len);
+ } else {
+ av_assert0(fs->c.bytestream_end >= fs->c.bytestream_start + len);
+ av_assert0(fs->c.bytestream < fs->c.bytestream_start + len);
+ fs->c.bytestream_end = fs->c.bytestream_start + len;
+ }
}
avctx->execute(avctx, encode_slice, &f->slice_context[0], NULL,
f->slice_count, sizeof(void *));
diff --git a/libavcodec/fic.c b/libavcodec/fic.c
index 7d698f08d9..e58d3b99e2 100644
--- a/libavcodec/fic.c
+++ b/libavcodec/fic.c
@@ -94,8 +94,8 @@ static av_always_inline void fic_idct(int16_t *blk, int step, int shift, int rnd
const int t7 = t3 - t1;
const int t8 = 17734 * blk[2 * step] - 42813 * blk[6 * step];
const int t9 = 17734 * blk[6 * step] + 42814 * blk[2 * step];
- const int tA = (blk[0 * step] - blk[4 * step] << 15) + rnd;
- const int tB = (blk[0 * step] + blk[4 * step] << 15) + rnd;
+ const int tA = (blk[0 * step] - blk[4 * step]) * 32768 + rnd;
+ const int tB = (blk[0 * step] + blk[4 * step]) * 32768 + rnd;
blk[0 * step] = ( t4 + t9 + tB) >> shift;
blk[1 * step] = ( t6 + t7 + t8 + tA) >> shift;
blk[2 * step] = ( t6 - t7 - t8 + tA) >> shift;
diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c
index 183fe6e5c9..6df531b7b3 100644
--- a/libavcodec/flac_parser.c
+++ b/libavcodec/flac_parser.c
@@ -586,10 +586,12 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
temp = curr->next;
av_freep(&curr->link_penalty);
av_free(curr);
+ fpc->nb_headers_buffered--;
}
fpc->headers = fpc->best_header->next;
av_freep(&fpc->best_header->link_penalty);
av_freep(&fpc->best_header);
+ fpc->nb_headers_buffered--;
}
/* Find and score new headers. */
diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
index b7237e18f0..c372c1b91d 100644
--- a/libavcodec/flacdec.c
+++ b/libavcodec/flacdec.c
@@ -201,12 +201,12 @@ static int get_metadata_size(const uint8_t *buf, int buf_size)
buf += 4;
do {
if (buf_end - buf < 4)
- return 0;
+ return AVERROR_INVALIDDATA;
flac_parse_block_header(buf, &metadata_last, NULL, &metadata_size);
buf += 4;
if (buf_end - buf < metadata_size) {
/* need more data in order to read the complete header */
- return 0;
+ return AVERROR_INVALIDDATA;
}
buf += metadata_size;
} while (!metadata_last);
@@ -268,7 +268,8 @@ static int decode_subframe_fixed(FLACContext *s, int32_t *decoded,
int pred_order, int bps)
{
const int blocksize = s->blocksize;
- int av_uninit(a), av_uninit(b), av_uninit(c), av_uninit(d), i;
+ unsigned av_uninit(a), av_uninit(b), av_uninit(c), av_uninit(d);
+ int i;
int ret;
/* warm up samples */
@@ -447,7 +448,7 @@ static inline int decode_subframe(FLACContext *s, int channel)
if (wasted) {
int i;
for (i = 0; i < s->blocksize; i++)
- decoded[i] <<= wasted;
+ decoded[i] = (unsigned)decoded[i] << wasted;
}
return 0;
diff --git a/libavcodec/flacdsp_template.c b/libavcodec/flacdsp_template.c
index 62c0a15ff6..776c78da71 100644
--- a/libavcodec/flacdsp_template.c
+++ b/libavcodec/flacdsp_template.c
@@ -56,7 +56,7 @@ static void FUNC(flac_decorrelate_indep_c)(uint8_t **out, int32_t **in,
for (j = 0; j < len; j++)
for (i = 0; i < channels; i++)
- S(samples, i, j) = in[i][j] << shift;
+ S(samples, i, j) = (int)((unsigned)in[i][j] << shift);
}
static void FUNC(flac_decorrelate_ls_c)(uint8_t **out, int32_t **in,
diff --git a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c
index 3e0573af93..6f0961ce96 100644
--- a/libavcodec/flicvideo.c
+++ b/libavcodec/flicvideo.c
@@ -202,6 +202,9 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
num_chunks = bytestream2_get_le16(&g2);
bytestream2_skip(&g2, 8); /* skip padding */
+ if (frame_size < 16)
+ return AVERROR_INVALIDDATA;
+
frame_size -= 16;
/* iterate through the chunks */
@@ -520,6 +523,8 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
if (frame_size > buf_size)
frame_size = buf_size;
+ if (frame_size < 16)
+ return AVERROR_INVALIDDATA;
frame_size -= 16;
/* iterate through the chunks */
diff --git a/libavcodec/g722.c b/libavcodec/g722.c
index ee3b85f845..ef7ca6d446 100644
--- a/libavcodec/g722.c
+++ b/libavcodec/g722.c
@@ -88,14 +88,14 @@ static inline void s_zero(int cur_diff, struct G722Band *band)
ACCUM(3, band->diff_mem[2], 1);
ACCUM(2, band->diff_mem[1], 1);
ACCUM(1, band->diff_mem[0], 1);
- ACCUM(0, cur_diff << 1, 1);
+ ACCUM(0, cur_diff * 2, 1);
} else {
ACCUM(5, band->diff_mem[4], 0);
ACCUM(4, band->diff_mem[3], 0);
ACCUM(3, band->diff_mem[2], 0);
ACCUM(2, band->diff_mem[1], 0);
ACCUM(1, band->diff_mem[0], 0);
- ACCUM(0, cur_diff << 1, 0);
+ ACCUM(0, cur_diff * 2, 0);
}
#undef ACCUM
band->s_zero = s_zero;
@@ -119,14 +119,14 @@ static void do_adaptive_prediction(struct G722Band *band, const int cur_diff)
band->part_reconst_mem[0] = cur_part_reconst;
band->pole_mem[1] = av_clip((sg[0] * av_clip(band->pole_mem[0], -8191, 8191) >> 5) +
- (sg[1] << 7) + (band->pole_mem[1] * 127 >> 7), -12288, 12288);
+ (sg[1] * 128) + (band->pole_mem[1] * 127 >> 7), -12288, 12288);
limit = 15360 - band->pole_mem[1];
band->pole_mem[0] = av_clip(-192 * sg[0] + (band->pole_mem[0] * 255 >> 8), -limit, limit);
s_zero(cur_diff, band);
- cur_qtzd_reconst = av_clip_int16((band->s_predictor + cur_diff) << 1);
+ cur_qtzd_reconst = av_clip_int16((band->s_predictor + cur_diff) * 2);
band->s_predictor = av_clip_int16(band->s_zero +
(band->pole_mem[0] * cur_qtzd_reconst >> 15) +
(band->pole_mem[1] * band->prev_qtzd_reconst >> 15));
diff --git a/libavcodec/g723_1.c b/libavcodec/g723_1.c
index a11fec8a9e..78ce922266 100644
--- a/libavcodec/g723_1.c
+++ b/libavcodec/g723_1.c
@@ -41,7 +41,7 @@ int ff_g723_1_scale_vector(int16_t *dst, const int16_t *vector, int length)
bits= FFMAX(bits, 0);
for (i = 0; i < length; i++)
- dst[i] = vector[i] << bits >> 3;
+ dst[i] = (vector[i] * (1 << bits)) >> 3;
return bits - 3;
}
@@ -125,9 +125,9 @@ static void lsp2lpc(int16_t *lpc)
for (j = 0; j < LPC_ORDER; j++) {
int index = (lpc[j] >> 7) & 0x1FF;
int offset = lpc[j] & 0x7f;
- int temp1 = cos_tab[index] << 16;
+ int temp1 = cos_tab[index] * (1 << 16);
int temp2 = (cos_tab[index + 1] - cos_tab[index]) *
- ((offset << 8) + 0x80) << 1;
+ (((offset << 8) + 0x80) << 1);
lpc[j] = -(av_sat_dadd32(1 << 15, temp1 + temp2) >> 16);
}
@@ -138,11 +138,11 @@ static void lsp2lpc(int16_t *lpc)
*/
/* Initialize with values in Q28 */
f1[0] = 1 << 28;
- f1[1] = (lpc[0] << 14) + (lpc[2] << 14);
+ f1[1] = (lpc[0] + lpc[2]) * (1 << 14);
f1[2] = lpc[0] * lpc[2] + (2 << 28);
f2[0] = 1 << 28;
- f2[1] = (lpc[1] << 14) + (lpc[3] << 14);
+ f2[1] = (lpc[1] + lpc[3]) * (1 << 14);
f2[2] = lpc[1] * lpc[3] + (2 << 28);
/*
@@ -162,8 +162,8 @@ static void lsp2lpc(int16_t *lpc)
f1[0] >>= 1;
f2[0] >>= 1;
- f1[1] = ((lpc[2 * i] << 16 >> i) + f1[1]) >> 1;
- f2[1] = ((lpc[2 * i + 1] << 16 >> i) + f2[1]) >> 1;
+ f1[1] = ((lpc[2 * i] * 65536 >> i) + f1[1]) >> 1;
+ f2[1] = ((lpc[2 * i + 1] * 65536 >> i) + f2[1]) >> 1;
}
/* Convert polynomial coefficients to LPC coefficients */
@@ -171,8 +171,8 @@ static void lsp2lpc(int16_t *lpc)
int64_t ff1 = f1[i + 1] + f1[i];
int64_t ff2 = f2[i + 1] - f2[i];
- lpc[i] = av_clipl_int32(((ff1 + ff2) << 3) + (1 << 15)) >> 16;
- lpc[LPC_ORDER - i - 1] = av_clipl_int32(((ff1 - ff2) << 3) +
+ lpc[i] = av_clipl_int32(((ff1 + ff2) * 8) + (1 << 15)) >> 16;
+ lpc[LPC_ORDER - i - 1] = av_clipl_int32(((ff1 - ff2) * 8) +
(1 << 15)) >> 16;
}
}
diff --git a/libavcodec/g723_1.h b/libavcodec/g723_1.h
index 40d6e700b1..f833af01c6 100644
--- a/libavcodec/g723_1.h
+++ b/libavcodec/g723_1.h
@@ -55,7 +55,7 @@
* @param b 16 bit multiplier
*/
#define MULL2(a, b) \
- ((((a) >> 16) * (b) << 1) + (((a) & 0xffff) * (b) >> 15))
+ ((((a) >> 16) * (b) * 2) + (((a) & 0xffff) * (b) >> 15))
/**
* G723.1 frame types
diff --git a/libavcodec/g723_1dec.c b/libavcodec/g723_1dec.c
index 3e8c4897d2..36b9197cf1 100644
--- a/libavcodec/g723_1dec.c
+++ b/libavcodec/g723_1dec.c
@@ -487,7 +487,7 @@ static void residual_interp(int16_t *buf, int16_t *out, int lag,
(FRAME_LEN - lag) * sizeof(*out));
} else { /* Unvoiced */
for (i = 0; i < FRAME_LEN; i++) {
- *rseed = *rseed * 521 + 259;
+ *rseed = (int16_t)(*rseed * 521 + 259);
out[i] = gain * *rseed >> 15;
}
memset(buf, 0, (FRAME_LEN + PITCH_MAX) * sizeof(*buf));
@@ -516,7 +516,7 @@ static void residual_interp(int16_t *buf, int16_t *out, int lag,
(iir_coef)[n - 1] * ((dest)[m - n] >> in_shift);\
}\
\
- (dest)[m] = av_clipl_int32(((src)[m] << 16) + (filter << 3) +\
+ (dest)[m] = av_clipl_int32(((src)[m] * 65536) + (filter * 8) +\
(1 << 15)) >> res_shift;\
}\
}
@@ -663,7 +663,7 @@ static int estimate_sid_gain(G723_1_Context *p)
t = p->sid_gain << shift;
else
t = p->sid_gain >> -shift;
- x = t * cng_filt[0] >> 16;
+ x = av_clipl_int32(t * (int64_t)cng_filt[0] >> 16);
if (x >= cng_bseg[2])
return 0x3F;
@@ -694,13 +694,13 @@ static int estimate_sid_gain(G723_1_Context *p)
if (y <= 0) {
t = seg * 32 + (val + 1 << seg2);
t = t * t - x;
- val = (seg2 - 1 << 4) + val;
+ val = (seg2 - 1) * 16 + val;
if (t >= y)
val++;
} else {
t = seg * 32 + (val - 1 << seg2);
t = t * t - x;
- val = (seg2 - 1 << 4) + val;
+ val = (seg2 - 1) * 16 + val;
if (t >= y)
val--;
}
@@ -732,7 +732,7 @@ static void generate_noise(G723_1_Context *p)
off[i * 2 + 1] = ((t >> 1) & 1) + SUBFRAME_LEN;
t >>= 2;
for (j = 0; j < 11; j++) {
- signs[i * 11 + j] = (t & 1) * 2 - 1 << 14;
+ signs[i * 11 + j] = ((t & 1) * 2 - 1) * (1 << 14);
t >>= 1;
}
}
@@ -776,7 +776,7 @@ static void generate_noise(G723_1_Context *p)
sum = 0;
if (shift < 0) {
for (j = 0; j < SUBFRAME_LEN * 2; j++) {
- t = vector_ptr[j] << -shift;
+ t = vector_ptr[j] * (1 << -shift);
sum += t * t;
tmp[j] = t;
}
@@ -814,7 +814,7 @@ static void generate_noise(G723_1_Context *p)
if (shift < 0)
x >>= -shift;
else
- x <<= shift;
+ x *= 1 << shift;
x = av_clip(x, -10000, 10000);
for (j = 0; j < 11; j++) {
@@ -903,7 +903,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
&p->subframe[i], p->cur_rate);
/* Get the total excitation */
for (j = 0; j < SUBFRAME_LEN; j++) {
- int v = av_clip_int16(vector_ptr[j] << 1);
+ int v = av_clip_int16(vector_ptr[j] * 2);
vector_ptr[j] = av_clip_int16(v + acb_vector[j]);
}
vector_ptr += SUBFRAME_LEN;
diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index f3de9e715d..4be44b23d0 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -269,7 +269,7 @@ static int16_t g726_decode(G726Context* c, int I)
c->se += mult(i2f(c->a[i] >> 2, &f), &c->sr[i]);
c->se >>= 1;
- return av_clip(re_signal << 2, -0xffff, 0xffff);
+ return av_clip(re_signal * 4, -0xffff, 0xffff);
}
static av_cold int g726_reset(G726Context *c)
diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index 4cf61d6f1b..30e9da311f 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -382,6 +382,10 @@ static inline uint64_t get_bits64(GetBitContext *s, int n)
*/
static inline int get_sbits_long(GetBitContext *s, int n)
{
+ // sign_extend(x, 0) is undefined
+ if (!n)
+ return 0;
+
return sign_extend(get_bits_long(s, n), n);
}
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index b979b15382..550a7fc15e 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1591,7 +1591,9 @@ again:
#endif
} else
context_count++;
- }
+ } else
+ sl->ref_count[0] = sl->ref_count[1] = 0;
+ break;
break;
case NAL_DPA:
case NAL_DPB:
diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c
index deab35a3d9..4adbbde8b7 100644
--- a/libavcodec/h264_cabac.c
+++ b/libavcodec/h264_cabac.c
@@ -1744,7 +1744,7 @@ decode_cabac_residual_internal(const H264Context *h, H264SliceContext *sl,
while( j-- ) { \
coeff_abs += coeff_abs + get_cabac_bypass( CC ); \
} \
- coeff_abs+= 14; \
+ coeff_abs+= 14U; \
} \
\
if( is_dc ) { \
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index b0251f405c..7a7dd397d8 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -1114,7 +1114,7 @@ decode_intra_mb:
dquant= get_se_golomb(&sl->gb);
- sl->qscale += dquant;
+ sl->qscale += (unsigned)dquant;
if (((unsigned)sl->qscale) > max_qp){
if (sl->qscale < 0) sl->qscale += max_qp + 1;
diff --git a/libavcodec/h264_direct.c b/libavcodec/h264_direct.c
index 5f66a67d89..2660cb80d3 100644
--- a/libavcodec/h264_direct.c
+++ b/libavcodec/h264_direct.c
@@ -613,7 +613,7 @@ single_col:
{
const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride];
- int my_col = (mv_col[1] << y_shift) / 2;
+ int my_col = (mv_col[1] * (1 << y_shift)) / 2;
int mx = (scale * mv_col[0] + 128) >> 8;
int my = (scale * my_col + 128) >> 8;
fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8,
diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h
index 763746cc26..18de4b0bbc 100644
--- a/libavcodec/h264_mvpred.h
+++ b/libavcodec/h264_mvpred.h
@@ -68,7 +68,7 @@ static av_always_inline int fetch_diagonal_mv(const H264Context *h, H264SliceCon
}
if (MB_FIELD(sl) && !IS_INTERLACED(sl->left_type[0])) {
// left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK.
- SET_DIAG_MV(/ 2, << 1, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3);
+ SET_DIAG_MV(/ 2, *2, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3);
}
}
#undef SET_DIAG_MV
@@ -248,7 +248,7 @@ static av_always_inline void pred_8x16_motion(const H264Context *const h,
if (IS_INTERLACED(type)) { \
refn >>= 1; \
AV_COPY32(mvbuf[idx], mvn); \
- mvbuf[idx][1] <<= 1; \
+ mvbuf[idx][1] *= 2; \
mvn = mvbuf[idx]; \
} \
} \
diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index f598b6393a..9cf5e80010 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -145,7 +145,7 @@ static int decode_nal_sei_display_orientation(HEVCContext *s)
return 0;
}
-static int decode_pic_timing(HEVCContext *s)
+static int decode_pic_timing(HEVCContext *s, int size)
{
GetBitContext *gb = &s->HEVClc->gb;
HEVCSPS *sps;
@@ -166,8 +166,12 @@ static int decode_pic_timing(HEVCContext *s)
}
get_bits(gb, 2); // source_scan_type
get_bits(gb, 1); // duplicate_flag
+ skip_bits1(gb);
+ size--;
}
- return 1;
+ skip_bits_long(gb, 8 * size);
+
+ return 0;
}
static int decode_registered_user_data_closed_caption(HEVCContext *s, int size)
@@ -297,9 +301,8 @@ static int decode_nal_sei_prefix(HEVCContext *s, int type, int size)
return decode_nal_sei_display_orientation(s);
case SEI_TYPE_PICTURE_TIMING:
{
- int ret = decode_pic_timing(s);
+ int ret = decode_pic_timing(s, size);
av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
- skip_bits(gb, 8 * size);
return ret;
}
case SEI_TYPE_MASTERING_DISPLAY_INFO:
diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c
index 3ef83d4eb4..d18464769d 100644
--- a/libavcodec/hq_hqa.c
+++ b/libavcodec/hq_hqa.c
@@ -67,11 +67,11 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64],
memset(block, 0, 64 * sizeof(*block));
if (!is_hqa) {
- block[0] = get_sbits(gb, 9) << 6;
+ block[0] = get_sbits(gb, 9) * 64;
q = ff_hq_quants[qsel][is_chroma][get_bits(gb, 2)];
} else {
q = ff_hq_quants[qsel][is_chroma][get_bits(gb, 2)];
- block[0] = get_sbits(gb, 9) << 6;
+ block[0] = get_sbits(gb, 9) * 64;
}
for (;;) {
@@ -82,7 +82,7 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64],
pos += ff_hq_ac_skips[val];
if (pos >= 64)
break;
- block[ff_zigzag_direct[pos]] = (ff_hq_ac_syms[val] * q[pos]) >> 12;
+ block[ff_zigzag_direct[pos]] = (int)(ff_hq_ac_syms[val] * (unsigned)q[pos]) >> 12;
pos++;
}
diff --git a/libavcodec/hqxdsp.c b/libavcodec/hqxdsp.c
index feff9c0b68..7f8044e463 100644
--- a/libavcodec/hqxdsp.c
+++ b/libavcodec/hqxdsp.c
@@ -39,18 +39,18 @@ static inline void idct_col(int16_t *blk, const uint8_t *quant)
s6 = (int) blk[6 * 8] * quant[6 * 8];
s7 = (int) blk[7 * 8] * quant[7 * 8];
- t0 = (s3 * 19266 + s5 * 12873) >> 15;
- t1 = (s5 * 19266 - s3 * 12873) >> 15;
- t2 = ((s7 * 4520 + s1 * 22725) >> 15) - t0;
- t3 = ((s1 * 4520 - s7 * 22725) >> 15) - t1;
+ t0 = (int)(s3 * 19266U + s5 * 12873U) >> 15;
+ t1 = (int)(s5 * 19266U - s3 * 12873U) >> 15;
+ t2 = ((int)(s7 * 4520U + s1 * 22725U) >> 15) - t0;
+ t3 = ((int)(s1 * 4520U - s7 * 22725U) >> 15) - t1;
t4 = t0 * 2 + t2;
t5 = t1 * 2 + t3;
t6 = t2 - t3;
t7 = t3 * 2 + t6;
- t8 = (t6 * 11585) >> 14;
- t9 = (t7 * 11585) >> 14;
- tA = (s2 * 8867 - s6 * 21407) >> 14;
- tB = (s6 * 8867 + s2 * 21407) >> 14;
+ t8 = (int)(t6 * 11585U) >> 14;
+ t9 = (int)(t7 * 11585U) >> 14;
+ tA = (int)(s2 * 8867U - s6 * 21407U) >> 14;
+ tB = (int)(s6 * 8867U + s2 * 21407U) >> 14;
tC = (s0 >> 1) - (s4 >> 1);
tD = (s4 >> 1) * 2 + tC;
tE = tC - (tA >> 1);
diff --git a/libavcodec/htmlsubtitles.c b/libavcodec/htmlsubtitles.c
index a2cd40fad3..16295daa0c 100644
--- a/libavcodec/htmlsubtitles.c
+++ b/libavcodec/htmlsubtitles.c
@@ -46,11 +46,12 @@ typedef struct SrtStack {
static void rstrip_spaces_buf(AVBPrint *buf)
{
- while (buf->len > 0 && buf->str[buf->len - 1] == ' ')
- buf->str[--buf->len] = 0;
+ if (av_bprint_is_complete(buf))
+ while (buf->len > 0 && buf->str[buf->len - 1] == ' ')
+ buf->str[--buf->len] = 0;
}
-void ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)
+int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)
{
char *param, buffer[128], tmp[128];
int len, tag_close, sptr = 1, line_start = 1, an = 0, end = 0;
@@ -146,7 +147,7 @@ void ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)
if (stack[sptr].param[i][0])
av_bprintf(dst, "%s", stack[sptr].param[i]);
}
- } else if (!tagname[1] && strspn(tagname, "bisu") == 1) {
+ } else if (tagname[0] && !tagname[1] && strspn(tagname, "bisu") == 1) {
av_bprintf(dst, "{\\%c%d}", tagname[0], !tag_close);
} else {
unknown = 1;
@@ -171,8 +172,13 @@ void ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)
line_start = 0;
}
+ if (!av_bprint_is_complete(dst))
+ return AVERROR(ENOMEM);
+
while (dst->len >= 2 && !strncmp(&dst->str[dst->len - 2], "\\N", 2))
dst->len -= 2;
dst->str[dst->len] = 0;
rstrip_spaces_buf(dst);
+
+ return 0;
}
diff --git a/libavcodec/htmlsubtitles.h b/libavcodec/htmlsubtitles.h
index e10cdda241..f3a8ef5d8b 100644
--- a/libavcodec/htmlsubtitles.h
+++ b/libavcodec/htmlsubtitles.h
@@ -23,6 +23,6 @@
#include "libavutil/bprint.h"
-void ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in);
+int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in);
#endif /* AVCODEC_HTMLSUBTITLES_H */
diff --git a/libavcodec/idcinvideo.c b/libavcodec/idcinvideo.c
index 4a0a6fb6c0..014a3c3ed5 100644
--- a/libavcodec/idcinvideo.c
+++ b/libavcodec/idcinvideo.c
@@ -214,7 +214,8 @@ static int idcin_decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
IdcinContext *s = avctx->priv_data;
- const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+ int pal_size;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size);
AVFrame *frame = data;
int ret;
@@ -227,9 +228,11 @@ static int idcin_decode_frame(AVCodecContext *avctx,
if (idcin_decode_vlcs(s, frame))
return AVERROR_INVALIDDATA;
- if (pal) {
+ if (pal && pal_size == AVPALETTE_SIZE) {
frame->palette_has_changed = 1;
memcpy(s->pal, pal, AVPALETTE_SIZE);
+ } else if (pal) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size);
}
/* make the palette available on the way out */
memcpy(frame->data[1], s->pal, AVPALETTE_SIZE);
diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c
index 7ad686d50b..d99ad18f0e 100644
--- a/libavcodec/indeo2.c
+++ b/libavcodec/indeo2.c
@@ -68,6 +68,8 @@ static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst
for (i = 0; i < c * 2; i++)
dst[out++] = 0x80;
} else { /* copy two values from table */
+ if (c <= 0)
+ return AVERROR_INVALIDDATA;
dst[out++] = table[c * 2];
dst[out++] = table[(c * 2) + 1];
}
@@ -76,6 +78,8 @@ static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst
for (j = 1; j < height; j++) {
out = 0;
+ if (get_bits_left(&ctx->gb) <= 0)
+ return AVERROR_INVALIDDATA;
while (out < width) {
int c = ir2_get_code(&ctx->gb);
if (c >= 0x80) { /* we have a skip */
@@ -87,7 +91,10 @@ static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst
out++;
}
} else { /* add two deltas from table */
- int t = dst[out - pitch] + (table[c * 2] - 128);
+ int t;
+ if (c <= 0)
+ return AVERROR_INVALIDDATA;
+ t = dst[out - pitch] + (table[c * 2] - 128);
t = av_clip_uint8(t);
dst[out] = t;
out++;
@@ -115,12 +122,16 @@ static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_
for (j = 0; j < height; j++) {
out = 0;
+ if (get_bits_left(&ctx->gb) <= 0)
+ return AVERROR_INVALIDDATA;
while (out < width) {
c = ir2_get_code(&ctx->gb);
if (c >= 0x80) { /* we have a skip */
c -= 0x7F;
out += c * 2;
} else { /* add two deltas from table */
+ if (c <= 0)
+ return AVERROR_INVALIDDATA;
t = dst[out] + (((table[c * 2] - 128)*3) >> 2);
t = av_clip_uint8(t);
dst[out] = t;
diff --git a/libavcodec/interplayacm.c b/libavcodec/interplayacm.c
index a676bcb931..8b340093df 100644
--- a/libavcodec/interplayacm.c
+++ b/libavcodec/interplayacm.c
@@ -61,6 +61,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
if (avctx->extradata_size < 14)
return AVERROR_INVALIDDATA;
+ if (avctx->channels <= 0) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid number of channels: %d\n", avctx->channels);
+ return AVERROR_INVALIDDATA;
+ }
+
s->level = AV_RL16(avctx->extradata + 12) & 0xf;
s->rows = AV_RL16(avctx->extradata + 12) >> 4;
s->cols = 1 << s->level;
@@ -71,7 +76,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
s->block = av_calloc(s->block_len, sizeof(int));
s->wrapbuf = av_calloc(s->wrapbuf_len, sizeof(int));
s->ampbuf = av_calloc(0x10000, sizeof(int));
- s->bitstream = av_calloc(s->max_framesize, sizeof(*s->bitstream));
+ s->bitstream = av_calloc(s->max_framesize + AV_INPUT_BUFFER_PADDING_SIZE / sizeof(*s->bitstream) + 1, sizeof(*s->bitstream));
if (!s->block || !s->wrapbuf || !s->ampbuf || !s->bitstream)
return AVERROR(ENOMEM);
@@ -325,6 +330,10 @@ static int t15(InterplayACMContext *s, unsigned ind, unsigned col)
for (i = 0; i < s->rows; i++) {
/* b = (x1) + (x2 * 3) + (x3 * 9) */
b = get_bits(gb, 5);
+ if (b > 26) {
+ av_log(NULL, AV_LOG_ERROR, "Too large b = %d > 26\n", b);
+ return AVERROR_INVALIDDATA;
+ }
n1 = (mul_3x3[b] & 0x0F) - 1;
n2 = ((mul_3x3[b] >> 4) & 0x0F) - 1;
@@ -350,6 +359,10 @@ static int t27(InterplayACMContext *s, unsigned ind, unsigned col)
for (i = 0; i < s->rows; i++) {
/* b = (x1) + (x2 * 5) + (x3 * 25) */
b = get_bits(gb, 7);
+ if (b > 124) {
+ av_log(NULL, AV_LOG_ERROR, "Too large b = %d > 124\n", b);
+ return AVERROR_INVALIDDATA;
+ }
n1 = (mul_3x5[b] & 0x0F) - 2;
n2 = ((mul_3x5[b] >> 4) & 0x0F) - 2;
@@ -374,6 +387,10 @@ static int t37(InterplayACMContext *s, unsigned ind, unsigned col)
for (i = 0; i < s->rows; i++) {
/* b = (x1) + (x2 * 11) */
b = get_bits(gb, 7);
+ if (b > 120) {
+ av_log(NULL, AV_LOG_ERROR, "Too large b = %d > 120\n", b);
+ return AVERROR_INVALIDDATA;
+ }
n1 = (mul_2x11[b] & 0x0F) - 5;
n2 = ((mul_2x11[b] >> 4) & 0x0F) - 5;
diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c
index 1460741a53..48dc3783b4 100644
--- a/libavcodec/interplayvideo.c
+++ b/libavcodec/interplayvideo.c
@@ -988,6 +988,11 @@ static int ipvideo_decode_frame(AVCodecContext *avctx,
AVFrame *frame = data;
int ret;
+ if (av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, NULL)) {
+ av_frame_unref(s->last_frame);
+ av_frame_unref(s->second_last_frame);
+ }
+
if (buf_size < 2)
return AVERROR_INVALIDDATA;
@@ -999,10 +1004,6 @@ static int ipvideo_decode_frame(AVCodecContext *avctx,
if (buf_size < s->decoding_map_size + 2)
return buf_size;
- if (av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, NULL)) {
- av_frame_unref(s->last_frame);
- av_frame_unref(s->second_last_frame);
- }
s->decoding_map = buf + 2;
bytestream2_init(&s->stream_ptr, buf + 2 + s->decoding_map_size,
@@ -1012,10 +1013,13 @@ static int ipvideo_decode_frame(AVCodecContext *avctx,
return ret;
if (!s->is_16bpp) {
- const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
- if (pal) {
+ int size;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size);
+ if (pal && size == AVPALETTE_SIZE) {
frame->palette_has_changed = 1;
memcpy(s->pal, pal, AVPALETTE_SIZE);
+ } else if (pal) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
}
}
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 2e449f8eeb..2d83bf3d30 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -167,6 +167,7 @@ static int h263_decode_gob_header(MpegEncContext *s)
/* We have a GBSC probably with GSTUFF */
skip_bits(&s->gb, 16); /* Drop the zeros */
left= get_bits_left(&s->gb);
+ left = FFMIN(left, 32);
//MN: we must check the bits left or we might end in a infinite loop (or segfault)
for(;left>13; left--){
if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
@@ -523,7 +524,7 @@ retry:
}else{
level = SHOW_UBITS(re, &s->gb, 5);
SKIP_CACHE(re, &s->gb, 5);
- level |= SHOW_SBITS(re, &s->gb, 6)<<5;
+ level |= SHOW_SBITS(re, &s->gb, 6) * (1<<5);
SKIP_COUNTER(re, &s->gb, 5 + 6);
}
}
diff --git a/libavcodec/ivi_dsp.c b/libavcodec/ivi_dsp.c
index 4b973992e0..6f79ada1d5 100644
--- a/libavcodec/ivi_dsp.c
+++ b/libavcodec/ivi_dsp.c
@@ -243,7 +243,7 @@ void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst,
#define INV_HAAR8(s1, s5, s3, s7, s2, s4, s6, s8,\
d1, d2, d3, d4, d5, d6, d7, d8,\
t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
- t1 = (s1) << 1; t5 = (s5) << 1;\
+ t1 = (s1) * 2; t5 = (s5) * 2;\
IVI_HAAR_BFLY(t1, t5, t1, t5, t0); IVI_HAAR_BFLY(t1, s3, t1, t3, t0);\
IVI_HAAR_BFLY(t5, s7, t5, t7, t0); IVI_HAAR_BFLY(t1, s2, t1, t2, t0);\
IVI_HAAR_BFLY(t3, s4, t3, t4, t0); IVI_HAAR_BFLY(t5, s6, t5, t6, t0);\
@@ -284,10 +284,10 @@ void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
if (flags[i]) {
/* pre-scaling */
shift = !(i & 4);
- sp1 = src[ 0] << shift;
- sp2 = src[ 8] << shift;
- sp3 = src[16] << shift;
- sp4 = src[24] << shift;
+ sp1 = src[ 0] * (1 << shift);
+ sp2 = src[ 8] * (1 << shift);
+ sp3 = src[16] * (1 << shift);
+ sp4 = src[24] * (1 << shift);
INV_HAAR8( sp1, sp2, sp3, sp4,
src[32], src[40], src[48], src[56],
dst[ 0], dst[ 8], dst[16], dst[24],
diff --git a/libavcodec/kmvc.c b/libavcodec/kmvc.c
index 7acaba7d21..ffe6a142e9 100644
--- a/libavcodec/kmvc.c
+++ b/libavcodec/kmvc.c
@@ -268,7 +268,8 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame,
int i, ret;
int header;
int blocksize;
- const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+ int pal_size;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size);
bytestream2_init(&ctx->g, avpkt->data, avpkt->size);
@@ -303,9 +304,11 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame,
}
}
- if (pal) {
+ if (pal && pal_size == AVPALETTE_SIZE) {
frame->palette_has_changed = 1;
memcpy(ctx->pal, pal, AVPALETTE_SIZE);
+ } else if (pal) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size);
}
if (ctx->setpal) {
diff --git a/libavcodec/lagarith.c b/libavcodec/lagarith.c
index 94d723d319..ea069b3d04 100644
--- a/libavcodec/lagarith.c
+++ b/libavcodec/lagarith.c
@@ -98,7 +98,7 @@ static uint32_t softfloat_mul(uint32_t x, uint64_t mantissa)
static uint8_t lag_calc_zero_run(int8_t x)
{
- return (x << 1) ^ (x >> 7);
+ return (x * 2) ^ (x >> 7);
}
static int lag_decode_prob(GetBitContext *gb, uint32_t *value)
@@ -191,7 +191,9 @@ static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb)
}
scale_factor++;
- cumulative_target = 1 << scale_factor;
+ if (scale_factor >= 32U)
+ return AVERROR_INVALIDDATA;
+ cumulative_target = 1U << scale_factor;
if (scaled_cumul_prob > cumulative_target) {
av_log(rac->avctx, AV_LOG_ERROR,
diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index cae3d20986..3f24a9c6cd 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -24,8 +24,6 @@
* JPEG 2000 decoder using libopenjpeg
*/
-#define OPJ_STATIC
-
#include "libavutil/common.h"
#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c
index 058ca363c8..2ca7b2d4d2 100644
--- a/libavcodec/libopenjpegenc.c
+++ b/libavcodec/libopenjpegenc.c
@@ -24,8 +24,6 @@
* JPEG 2000 encoder using libopenjpeg
*/
-#define OPJ_STATIC
-
#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/imgutils.h"
@@ -54,7 +52,9 @@
typedef struct LibOpenJPEGContext {
AVClass *avclass;
+#if OPENJPEG_MAJOR_VERSION == 1
opj_image_t *image;
+#endif // OPENJPEG_MAJOR_VERSION == 1
opj_cparameters_t enc_params;
#if OPENJPEG_MAJOR_VERSION == 1
opj_event_mgr_t event_mgr;
@@ -371,18 +371,22 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx)
cinema_parameters(&ctx->enc_params);
}
+#if OPENJPEG_MAJOR_VERSION == 1
ctx->image = mj2_create_image(avctx, &ctx->enc_params);
if (!ctx->image) {
av_log(avctx, AV_LOG_ERROR, "Error creating the mj2 image\n");
err = AVERROR(EINVAL);
goto fail;
}
+#endif // OPENJPEG_MAJOR_VERSION == 1
return 0;
fail:
+#if OPENJPEG_MAJOR_VERSION == 1
opj_image_destroy(ctx->image);
ctx->image = NULL;
+#endif // OPENJPEG_MAJOR_VERSION == 1
return err;
}
@@ -417,7 +421,7 @@ static int libopenjpeg_copy_packed8(AVCodecContext *avctx, const AVFrame *frame,
for (; y < image->comps[compno].h; ++y) {
image_line = image->comps[compno].data + y * image->comps[compno].w;
for (x = 0; x < image->comps[compno].w; ++x) {
- image_line[x] = image_line[x - image->comps[compno].w];
+ image_line[x] = image_line[x - (int)image->comps[compno].w];
}
}
}
@@ -457,7 +461,7 @@ static int libopenjpeg_copy_packed12(AVCodecContext *avctx, const AVFrame *frame
for (; y < image->comps[compno].h; ++y) {
image_line = image->comps[compno].data + y * image->comps[compno].w;
for (x = 0; x < image->comps[compno].w; ++x) {
- image_line[x] = image_line[x - image->comps[compno].w];
+ image_line[x] = image_line[x - (int)image->comps[compno].w];
}
}
}
@@ -497,7 +501,7 @@ static int libopenjpeg_copy_packed16(AVCodecContext *avctx, const AVFrame *frame
for (; y < image->comps[compno].h; ++y) {
image_line = image->comps[compno].data + y * image->comps[compno].w;
for (x = 0; x < image->comps[compno].w; ++x) {
- image_line[x] = image_line[x - image->comps[compno].w];
+ image_line[x] = image_line[x - (int)image->comps[compno].w];
}
}
}
@@ -524,8 +528,8 @@ static int libopenjpeg_copy_unpacked8(AVCodecContext *avctx, const AVFrame *fram
}
for (compno = 0; compno < numcomps; ++compno) {
- width = avctx->width / image->comps[compno].dx;
- height = avctx->height / image->comps[compno].dy;
+ width = (avctx->width + image->comps[compno].dx - 1) / image->comps[compno].dx;
+ height = (avctx->height + image->comps[compno].dy - 1) / image->comps[compno].dy;
for (y = 0; y < height; ++y) {
image_line = image->comps[compno].data + y * image->comps[compno].w;
frame_index = y * frame->linesize[compno];
@@ -538,7 +542,7 @@ static int libopenjpeg_copy_unpacked8(AVCodecContext *avctx, const AVFrame *fram
for (; y < image->comps[compno].h; ++y) {
image_line = image->comps[compno].data + y * image->comps[compno].w;
for (x = 0; x < image->comps[compno].w; ++x) {
- image_line[x] = image_line[x - image->comps[compno].w];
+ image_line[x] = image_line[x - (int)image->comps[compno].w];
}
}
}
@@ -566,8 +570,8 @@ static int libopenjpeg_copy_unpacked16(AVCodecContext *avctx, const AVFrame *fra
}
for (compno = 0; compno < numcomps; ++compno) {
- width = avctx->width / image->comps[compno].dx;
- height = avctx->height / image->comps[compno].dy;
+ width = (avctx->width + image->comps[compno].dx - 1) / image->comps[compno].dx;
+ height = (avctx->height + image->comps[compno].dy - 1) / image->comps[compno].dy;
frame_ptr = (uint16_t *)frame->data[compno];
for (y = 0; y < height; ++y) {
image_line = image->comps[compno].data + y * image->comps[compno].w;
@@ -581,7 +585,7 @@ static int libopenjpeg_copy_unpacked16(AVCodecContext *avctx, const AVFrame *fra
for (; y < image->comps[compno].h; ++y) {
image_line = image->comps[compno].data + y * image->comps[compno].w;
for (x = 0; x < image->comps[compno].w; ++x) {
- image_line[x] = image_line[x - image->comps[compno].w];
+ image_line[x] = image_line[x - (int)image->comps[compno].w];
}
}
}
@@ -593,18 +597,24 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet)
{
LibOpenJPEGContext *ctx = avctx->priv_data;
- opj_image_t *image = ctx->image;
+ int ret;
+ AVFrame *gbrframe;
+ int cpyresult = 0;
#if OPENJPEG_MAJOR_VERSION == 1
+ opj_image_t *image = ctx->image;
opj_cinfo_t *compress = NULL;
opj_cio_t *stream = NULL;
int len;
#else // OPENJPEG_MAJOR_VERSION == 2
opj_codec_t *compress = NULL;
opj_stream_t *stream = NULL;
+ opj_image_t *image = mj2_create_image(avctx, &ctx->enc_params);
+ if (!image) {
+ av_log(avctx, AV_LOG_ERROR, "Error creating the mj2 image\n");
+ ret = AVERROR(EINVAL);
+ goto done;
+ }
#endif // OPENJPEG_MAJOR_VERSION == 1
- int cpyresult = 0;
- int ret;
- AVFrame *gbrframe;
switch (avctx->pix_fmt) {
case AV_PIX_FMT_RGB24:
@@ -627,8 +637,10 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
case AV_PIX_FMT_GBRP14:
case AV_PIX_FMT_GBRP16:
gbrframe = av_frame_clone(frame);
- if (!gbrframe)
- return AVERROR(ENOMEM);
+ if (!gbrframe) {
+ ret = AVERROR(ENOMEM);
+ goto done;
+ }
gbrframe->data[0] = frame->data[2]; // swap to be rgb
gbrframe->data[1] = frame->data[0];
gbrframe->data[2] = frame->data[1];
@@ -685,19 +697,21 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
av_log(avctx, AV_LOG_ERROR,
"The frame's pixel format '%s' is not supported\n",
av_get_pix_fmt_name(avctx->pix_fmt));
- return AVERROR(EINVAL);
+ ret = AVERROR(EINVAL);
+ goto done;
break;
}
if (!cpyresult) {
av_log(avctx, AV_LOG_ERROR,
"Could not copy the frame data to the internal image buffer\n");
- return -1;
+ ret = -1;
+ goto done;
}
#if OPENJPEG_MAJOR_VERSION == 2
if ((ret = ff_alloc_packet2(avctx, pkt, 1024, 0)) < 0) {
- return ret;
+ goto done;
}
#endif // OPENJPEG_MAJOR_VERSION == 2
@@ -764,7 +778,7 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
#error Missing call to opj_stream_set_user_data
#endif
- if (!opj_start_compress(compress, ctx->image, stream) ||
+ if (!opj_start_compress(compress, image, stream) ||
!opj_encode(compress, stream) ||
!opj_end_compress(compress, stream)) {
av_log(avctx, AV_LOG_ERROR, "Error during the opj encode\n");
@@ -783,6 +797,7 @@ done:
#if OPENJPEG_MAJOR_VERSION == 2
opj_stream_destroy(stream);
opj_destroy_codec(compress);
+ opj_image_destroy(image);
#else
opj_cio_close(stream);
opj_destroy_compress(compress);
@@ -792,10 +807,12 @@ done:
static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx)
{
+#if OPENJPEG_MAJOR_VERSION == 1
LibOpenJPEGContext *ctx = avctx->priv_data;
opj_image_destroy(ctx->image);
ctx->image = NULL;
+#endif // OPENJPEG_MAJOR_VERSION == 1
return 0;
}
diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c
index 1e97604181..7dff9c16b7 100644
--- a/libavcodec/libopusdec.c
+++ b/libavcodec/libopusdec.c
@@ -47,6 +47,13 @@ static av_cold int libopus_decode_init(AVCodecContext *avc)
int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
+ avc->channels = avc->extradata_size >= 10 ? avc->extradata[9] : (avc->channels == 1) ? 1 : 2;
+ if (avc->channels <= 0) {
+ av_log(avc, AV_LOG_WARNING,
+ "Invalid number of channels %d, defaulting to stereo\n", avc->channels);
+ avc->channels = 2;
+ }
+
avc->sample_rate = 48000;
avc->sample_fmt = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;
diff --git a/libavcodec/libschroedingerdec.c b/libavcodec/libschroedingerdec.c
index 152cbe7d47..471077b2fe 100644
--- a/libavcodec/libschroedingerdec.c
+++ b/libavcodec/libschroedingerdec.c
@@ -218,6 +218,7 @@ static int libschroedinger_decode_frame(AVCodecContext *avctx,
int outer = 1;
SchroParseUnitContext parse_ctx;
LibSchroFrameContext *framewithpts = NULL;
+ int ret;
*got_frame = 0;
@@ -307,11 +308,10 @@ static int libschroedinger_decode_frame(AVCodecContext *avctx,
/* Grab next frame to be returned from the top of the queue. */
framewithpts = ff_schro_queue_pop(&p_schro_params->dec_frame_queue);
- if (framewithpts && framewithpts->frame) {
- int ret;
+ if (framewithpts && framewithpts->frame && framewithpts->frame->components[0].stride) {
if ((ret = ff_get_buffer(avctx, avframe, 0)) < 0)
- return ret;
+ goto end;
memcpy(avframe->data[0],
framewithpts->frame->components[0].data,
@@ -332,15 +332,17 @@ static int libschroedinger_decode_frame(AVCodecContext *avctx,
avframe->linesize[2] = framewithpts->frame->components[2].stride;
*got_frame = 1;
-
- /* Now free the frame resources. */
- libschroedinger_decode_frame_free(framewithpts->frame);
- av_free(framewithpts);
} else {
data = NULL;
*got_frame = 0;
}
- return buf_size;
+ ret = buf_size;
+end:
+ /* Now free the frame resources. */
+ if (framewithpts && framewithpts->frame)
+ libschroedinger_decode_frame_free(framewithpts->frame);
+ av_freep(&framewithpts);
+ return ret;
}
diff --git a/libavcodec/lzf.c b/libavcodec/lzf.c
index 409a7ffdd3..5b7526ef18 100644
--- a/libavcodec/lzf.c
+++ b/libavcodec/lzf.c
@@ -53,6 +53,7 @@ int ff_lzf_uncompress(GetByteContext *gb, uint8_t **buf, int64_t *size)
ret = av_reallocp(buf, *size);
if (ret < 0)
return ret;
+ p = *buf + len;
}
bytestream2_get_buffer(gb, p, s);
@@ -75,6 +76,7 @@ int ff_lzf_uncompress(GetByteContext *gb, uint8_t **buf, int64_t *size)
ret = av_reallocp(buf, *size);
if (ret < 0)
return ret;
+ p = *buf + len;
}
av_memcpy_backptr(p, off, l);
diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 1cc4ca4742..8e28aa04f0 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -73,7 +73,7 @@ static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n)
if (diff >= 0xffff)
return AVERROR_INVALIDDATA;
a->last_dc[component] += diff;
- block[0] = a->last_dc[component] << 3;
+ block[0] = a->last_dc[component] * (1 << 3);
}
i = 0;
@@ -111,11 +111,11 @@ static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n)
j = scantable[i];
if (level < 0) {
level = -level;
- level = (level * qscale * quant_matrix[j]) >> 3;
+ level = (level * (unsigned)qscale * quant_matrix[j]) >> 3;
level = (level - 1) | 1;
level = -level;
} else {
- level = (level * qscale * quant_matrix[j]) >> 3;
+ level = (level * (unsigned)qscale * quant_matrix[j]) >> 3;
level = (level - 1) | 1;
}
}
diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c
index 06fb393b92..ce649c602a 100644
--- a/libavcodec/mimic.c
+++ b/libavcodec/mimic.c
@@ -262,7 +262,7 @@ static int vlc_decode_block(MimicContext *ctx, int num_coeffs, int qscale)
coeff = vlcdec_lookup[num_bits][value];
if (pos < 3)
- coeff <<= 4;
+ coeff *= 16;
else /* TODO Use >> 10 instead of / 1001 */
coeff = (coeff * qscale) / 1001;
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index f002ccd866..e9705f2694 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -747,7 +747,8 @@ static int decode_block_progressive(MJpegDecodeContext *s, int16_t *block,
int16_t *quant_matrix,
int ss, int se, int Al, int *EOBRUN)
{
- int code, i, j, level, val, run;
+ int code, i, j, val, run;
+ unsigned level;
if (*EOBRUN) {
(*EOBRUN)--;
@@ -1076,6 +1077,10 @@ static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor,
for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
+ if (get_bits_left(&s->gb) < 1) {
+ av_log(s->avctx, AV_LOG_ERROR, "bitstream end in yuv_scan\n");
+ return AVERROR_INVALIDDATA;
+ }
if (s->restart_interval && !s->restart_count){
s->restart_count = s->restart_interval;
resync_mb_x = mb_x;
@@ -1127,7 +1132,7 @@ static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor,
if (s->interlaced && s->bottom_field)
ptr += linesize >> 1;
pred &= mask;
- *ptr= pred + (dc << point_transform);
+ *ptr= pred + ((unsigned)dc << point_transform);
}else{
ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
if(y==0 && toprow){
@@ -1147,7 +1152,7 @@ static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor,
if (s->interlaced && s->bottom_field)
ptr16 += linesize >> 1;
pred &= mask;
- *ptr16= pred + (dc << point_transform);
+ *ptr16= pred + ((unsigned)dc << point_transform);
}
if (++x == h) {
x = 0;
@@ -1186,13 +1191,13 @@ static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor,
PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
pred &= mask;
- *ptr = pred + (dc << point_transform);
+ *ptr = pred + ((unsigned)dc << point_transform);
}else{
ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);
pred &= mask;
- *ptr16= pred + (dc << point_transform);
+ *ptr16= pred + ((unsigned)dc << point_transform);
}
if (++x == h) {
@@ -1387,6 +1392,10 @@ static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss,
int block_idx = mb_y * s->block_stride[c];
int16_t (*block)[64] = &s->blocks[c][block_idx];
uint8_t *last_nnz = &s->last_nnz[c][block_idx];
+ if (get_bits_left(&s->gb) <= 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "bitstream truncated in mjpeg_decode_scan_progressive_ac\n");
+ return AVERROR_INVALIDDATA;
+ }
for (mb_x = 0; mb_x < s->mb_width; mb_x++, block++, last_nnz++) {
int ret;
if (s->restart_interval && !s->restart_count)
@@ -2366,7 +2375,7 @@ the_end:
}
}
}
- if (s->flipped) {
+ if (s->flipped && !s->rgb) {
int j;
avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, &vshift);
for (index=0; index<4; index++) {
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index c93b058dd7..5426712007 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -264,7 +264,7 @@ static inline int read_huff_channels(MLPDecodeContext *m, GetBitContext *gbp,
result = (result << lsb_bits) + get_bits(gbp, lsb_bits);
result += cp->sign_huff_offset;
- result <<= quant_step_size;
+ result *= 1 << quant_step_size;
m->sample_buffer[pos + s->blockpos][channel] = result;
}
@@ -684,7 +684,7 @@ static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp,
}
for (i = 0; i < order; i++)
- fcoeff[i] = get_sbits(gbp, coeff_bits) << coeff_shift;
+ fcoeff[i] = get_sbits(gbp, coeff_bits) * (1 << coeff_shift);
if (get_bits1(gbp)) {
int state_bits, state_shift;
@@ -701,7 +701,7 @@ static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp,
/* TODO: Check validity of state data. */
for (i = 0; i < order; i++)
- fp->state[i] = state_bits ? get_sbits(gbp, state_bits) << state_shift : 0;
+ fp->state[i] = state_bits ? get_sbits(gbp, state_bits) * (1 << state_shift) : 0;
}
}
@@ -759,7 +759,7 @@ static int read_matrix_params(MLPDecodeContext *m, unsigned int substr, GetBitCo
if (get_bits1(gbp))
coeff_val = get_sbits(gbp, frac_bits + 2);
- s->matrix_coeff[mat][ch] = coeff_val << (14 - frac_bits);
+ s->matrix_coeff[mat][ch] = coeff_val * (1 << (14 - frac_bits));
}
if (s->noise_type)
@@ -999,8 +999,8 @@ static void generate_2_noise_channels(MLPDecodeContext *m, unsigned int substr)
for (i = 0; i < s->blockpos; i++) {
uint16_t seed_shr7 = seed >> 7;
- m->sample_buffer[i][maxchan+1] = ((int8_t)(seed >> 15)) << s->noise_shift;
- m->sample_buffer[i][maxchan+2] = ((int8_t) seed_shr7) << s->noise_shift;
+ m->sample_buffer[i][maxchan+1] = ((int8_t)(seed >> 15)) * (1 << s->noise_shift);
+ m->sample_buffer[i][maxchan+2] = ((int8_t) seed_shr7) * (1 << s->noise_shift);
seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);
}
@@ -1162,6 +1162,11 @@ static int read_access_unit(AVCodecContext *avctx, void* data,
substr_header_size += 2;
}
+ if (length < header_size + substr_header_size) {
+ av_log(m->avctx, AV_LOG_ERROR, "Insuffient data for headers\n");
+ goto error;
+ }
+
if (!(nonrestart_substr ^ m->is_major_sync_unit)) {
av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\n");
goto error;
diff --git a/libavcodec/mlpdsp.c b/libavcodec/mlpdsp.c
index 3ae8c37708..2fc453c1f0 100644
--- a/libavcodec/mlpdsp.c
+++ b/libavcodec/mlpdsp.c
@@ -113,8 +113,8 @@ int32_t ff_mlp_pack_output(int32_t lossless_check_data,
for (i = 0; i < blockpos; i++) {
for (out_ch = 0; out_ch <= max_matrix_channel; out_ch++) {
int mat_ch = ch_assign[out_ch];
- int32_t sample = sample_buffer[i][mat_ch]
- << output_shift[mat_ch];
+ int32_t sample = sample_buffer[i][mat_ch] *
+ (1 << output_shift[mat_ch]);
lossless_check_data ^= (sample & 0xffffff) << mat_ch;
if (is32)
*data_32++ = sample << 8;
diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index 28f7b8f5be..6148593ade 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -115,6 +115,8 @@ static void mov_text_cleanup(MovTextContext *m)
av_freep(&m->s[i]);
}
av_freep(&m->s);
+ m->count_s = 0;
+ m->style_entries = 0;
}
}
@@ -278,12 +280,14 @@ static int decode_hclr(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
static int decode_styl(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
{
int i;
- m->style_entries = AV_RB16(tsmb);
+ int style_entries = AV_RB16(tsmb);
tsmb += 2;
// A single style record is of length 12 bytes.
- if (m->tracksize + m->size_var + 2 + m->style_entries * 12 > avpkt->size)
+ if (m->tracksize + m->size_var + 2 + style_entries * 12 > avpkt->size)
return -1;
+ m->style_entries = style_entries;
+
m->box_flags |= STYL_BOX;
for(i = 0; i < m->style_entries; i++) {
m->s_temp = av_malloc(sizeof(*m->s_temp));
@@ -477,10 +481,6 @@ static int mov_text_decode_frame(AVCodecContext *avctx,
tsmb_type = AV_RB32(tsmb);
tsmb += 4;
- if (tsmb_size == 0) {
- return AVERROR_INVALIDDATA;
- }
-
if (tsmb_size == 1) {
if (m->tracksize + 16 > avpkt->size)
break;
@@ -491,7 +491,12 @@ static int mov_text_decode_frame(AVCodecContext *avctx,
m->size_var = 8;
//size_var is equal to 8 or 16 depending on the size of box
- if (m->tracksize + tsmb_size > avpkt->size)
+ if (tsmb_size == 0) {
+ av_log(avctx, AV_LOG_ERROR, "tsmb_size is 0\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (tsmb_size > avpkt->size - m->tracksize)
break;
for (size_t i = 0; i < box_count; i++) {
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index cc8ace8e3a..4ac31d65c8 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -563,7 +563,7 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s,
dc = s->last_dc[component];
dc += diff;
s->last_dc[component] = dc;
- block[0] = dc << (3 - s->intra_dc_precision);
+ block[0] = dc * (1 << (3 - s->intra_dc_precision));
ff_tlog(s->avctx, "dc=%d\n", block[0]);
mismatch = block[0] ^ 1;
i = 0;
@@ -914,8 +914,8 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
s->last_mv[i][0][1]);
/* full_pel: only for MPEG-1 */
if (s->full_pel[i]) {
- s->mv[i][0][0] <<= 1;
- s->mv[i][0][1] <<= 1;
+ s->mv[i][0][0] *= 2;
+ s->mv[i][0][1] *= 2;
}
}
}
@@ -997,8 +997,8 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
dmy = get_dmv(s);
- s->last_mv[i][0][1] = my << my_shift;
- s->last_mv[i][1][1] = my << my_shift;
+ s->last_mv[i][0][1] = my * (1 << my_shift);
+ s->last_mv[i][1][1] = my * (1 << my_shift);
s->mv[i][0][0] = mx;
s->mv[i][0][1] = my;
@@ -1043,7 +1043,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
cbp = get_vlc2(&s->gb, ff_mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
if (mb_block_count > 6) {
- cbp <<= mb_block_count - 6;
+ cbp *= 1 << mb_block_count - 6;
cbp |= get_bits(&s->gb, mb_block_count - 6);
s->bdsp.clear_blocks(s->block[6]);
}
@@ -1291,7 +1291,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
// MPEG-1 aspect
- avctx->sample_aspect_ratio = av_d2q(1.0 / ff_mpeg1_aspect[s->aspect_ratio_info], 255);
+ AVRational aspect_inv = av_d2q(ff_mpeg1_aspect[s->aspect_ratio_info], 255);
+ avctx->sample_aspect_ratio = (AVRational) { aspect_inv.den, aspect_inv.num };
} else { // MPEG-2
// MPEG-2 aspect
if (s->aspect_ratio_info > 1) {
@@ -2432,7 +2433,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
#endif
s->closed_gop = get_bits1(&s->gb);
- /* broken_link indicate that after editing the
+ /* broken_link indicates that after editing the
* reference frames of the first B-Frames after GOP I-Frame
* are missing (open gop) */
broken_link = get_bits1(&s->gb);
@@ -2827,6 +2828,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx, void *data,
avctx->extradata, avctx->extradata_size);
if (*got_output) {
av_log(avctx, AV_LOG_ERROR, "picture in extradata\n");
+ av_frame_unref(picture);
*got_output = 0;
}
s->extradata_decoded = 1;
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 527cbe96c5..fc1c8297b9 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -178,6 +178,7 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g
int min_ab, i, w2, h2, w3, h3;
int sprite_ref[4][2];
int virtual_ref[2][2];
+ int64_t sprite_offset[2][2];
// only true for rectangle shapes
const int vop_ref[4][2] = { { 0, 0 }, { s->width, 0 },
@@ -257,10 +258,10 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g
switch (ctx->num_sprite_warping_points) {
case 0:
- s->sprite_offset[0][0] =
- s->sprite_offset[0][1] =
- s->sprite_offset[1][0] =
- s->sprite_offset[1][1] = 0;
+ sprite_offset[0][0] =
+ sprite_offset[0][1] =
+ sprite_offset[1][0] =
+ sprite_offset[1][1] = 0;
s->sprite_delta[0][0] = a;
s->sprite_delta[0][1] =
s->sprite_delta[1][0] = 0;
@@ -269,11 +270,11 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g
ctx->sprite_shift[1] = 0;
break;
case 1: // GMC only
- s->sprite_offset[0][0] = sprite_ref[0][0] - a * vop_ref[0][0];
- s->sprite_offset[0][1] = sprite_ref[0][1] - a * vop_ref[0][1];
- s->sprite_offset[1][0] = ((sprite_ref[0][0] >> 1) | (sprite_ref[0][0] & 1)) -
+ sprite_offset[0][0] = sprite_ref[0][0] - a * vop_ref[0][0];
+ sprite_offset[0][1] = sprite_ref[0][1] - a * vop_ref[0][1];
+ sprite_offset[1][0] = ((sprite_ref[0][0] >> 1) | (sprite_ref[0][0] & 1)) -
a * (vop_ref[0][0] / 2);
- s->sprite_offset[1][1] = ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] & 1)) -
+ sprite_offset[1][1] = ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] & 1)) -
a * (vop_ref[0][1] / 2);
s->sprite_delta[0][0] = a;
s->sprite_delta[0][1] =
@@ -283,22 +284,22 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g
ctx->sprite_shift[1] = 0;
break;
case 2:
- s->sprite_offset[0][0] = (sprite_ref[0][0] << (alpha + rho)) +
+ sprite_offset[0][0] = (sprite_ref[0][0] * (1 << alpha + rho)) +
(-r * sprite_ref[0][0] + virtual_ref[0][0]) *
(-vop_ref[0][0]) +
(r * sprite_ref[0][1] - virtual_ref[0][1]) *
(-vop_ref[0][1]) + (1 << (alpha + rho - 1));
- s->sprite_offset[0][1] = (sprite_ref[0][1] << (alpha + rho)) +
+ sprite_offset[0][1] = (sprite_ref[0][1] * (1 << alpha + rho)) +
(-r * sprite_ref[0][1] + virtual_ref[0][1]) *
(-vop_ref[0][0]) +
(-r * sprite_ref[0][0] + virtual_ref[0][0]) *
(-vop_ref[0][1]) + (1 << (alpha + rho - 1));
- s->sprite_offset[1][0] = ((-r * sprite_ref[0][0] + virtual_ref[0][0]) *
+ sprite_offset[1][0] = ((-r * sprite_ref[0][0] + virtual_ref[0][0]) *
(-2 * vop_ref[0][0] + 1) +
(r * sprite_ref[0][1] - virtual_ref[0][1]) *
(-2 * vop_ref[0][1] + 1) + 2 * w2 * r *
sprite_ref[0][0] - 16 * w2 + (1 << (alpha + rho + 1)));
- s->sprite_offset[1][1] = ((-r * sprite_ref[0][1] + virtual_ref[0][1]) *
+ sprite_offset[1][1] = ((-r * sprite_ref[0][1] + virtual_ref[0][1]) *
(-2 * vop_ref[0][0] + 1) +
(-r * sprite_ref[0][0] + virtual_ref[0][0]) *
(-2 * vop_ref[0][1] + 1) + 2 * w2 * r *
@@ -315,30 +316,22 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g
min_ab = FFMIN(alpha, beta);
w3 = w2 >> min_ab;
h3 = h2 >> min_ab;
- s->sprite_offset[0][0] = (sprite_ref[0][0] << (alpha + beta + rho - min_ab)) +
- (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
- h3 * (-vop_ref[0][0]) +
- (-r * sprite_ref[0][0] + virtual_ref[1][0]) *
- w3 * (-vop_ref[0][1]) +
- (1 << (alpha + beta + rho - min_ab - 1));
- s->sprite_offset[0][1] = (sprite_ref[0][1] << (alpha + beta + rho - min_ab)) +
- (-r * sprite_ref[0][1] + virtual_ref[0][1]) *
- h3 * (-vop_ref[0][0]) +
- (-r * sprite_ref[0][1] + virtual_ref[1][1]) *
- w3 * (-vop_ref[0][1]) +
- (1 << (alpha + beta + rho - min_ab - 1));
- s->sprite_offset[1][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
- h3 * (-2 * vop_ref[0][0] + 1) +
- (-r * sprite_ref[0][0] + virtual_ref[1][0]) *
- w3 * (-2 * vop_ref[0][1] + 1) + 2 * w2 * h3 *
- r * sprite_ref[0][0] - 16 * w2 * h3 +
- (1 << (alpha + beta + rho - min_ab + 1));
- s->sprite_offset[1][1] = (-r * sprite_ref[0][1] + virtual_ref[0][1]) *
- h3 * (-2 * vop_ref[0][0] + 1) +
- (-r * sprite_ref[0][1] + virtual_ref[1][1]) *
- w3 * (-2 * vop_ref[0][1] + 1) + 2 * w2 * h3 *
- r * sprite_ref[0][1] - 16 * w2 * h3 +
- (1 << (alpha + beta + rho - min_ab + 1));
+ sprite_offset[0][0] = ((int64_t)sprite_ref[0][0] * (1 << (alpha + beta + rho - min_ab))) +
+ ((int64_t)-r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-vop_ref[0][0]) +
+ ((int64_t)-r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-vop_ref[0][1]) +
+ ((int64_t)1 << (alpha + beta + rho - min_ab - 1));
+ sprite_offset[0][1] = ((int64_t)sprite_ref[0][1] * (1 << (alpha + beta + rho - min_ab))) +
+ ((int64_t)-r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-vop_ref[0][0]) +
+ ((int64_t)-r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-vop_ref[0][1]) +
+ ((int64_t)1 << (alpha + beta + rho - min_ab - 1));
+ sprite_offset[1][0] = ((int64_t)-r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-2 * vop_ref[0][0] + 1) +
+ ((int64_t)-r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-2 * vop_ref[0][1] + 1) +
+ (int64_t)2 * w2 * h3 * r * sprite_ref[0][0] - 16 * w2 * h3 +
+ ((int64_t)1 << (alpha + beta + rho - min_ab + 1));
+ sprite_offset[1][1] = ((int64_t)-r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-2 * vop_ref[0][0] + 1) +
+ ((int64_t)-r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-2 * vop_ref[0][1] + 1) +
+ (int64_t)2 * w2 * h3 * r * sprite_ref[0][1] - 16 * w2 * h3 +
+ ((int64_t)1 << (alpha + beta + rho - min_ab + 1));
s->sprite_delta[0][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]) * h3;
s->sprite_delta[0][1] = (-r * sprite_ref[0][0] + virtual_ref[1][0]) * w3;
s->sprite_delta[1][0] = (-r * sprite_ref[0][1] + virtual_ref[0][1]) * h3;
@@ -353,10 +346,10 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g
s->sprite_delta[0][1] == 0 &&
s->sprite_delta[1][0] == 0 &&
s->sprite_delta[1][1] == a << ctx->sprite_shift[0]) {
- s->sprite_offset[0][0] >>= ctx->sprite_shift[0];
- s->sprite_offset[0][1] >>= ctx->sprite_shift[0];
- s->sprite_offset[1][0] >>= ctx->sprite_shift[1];
- s->sprite_offset[1][1] >>= ctx->sprite_shift[1];
+ sprite_offset[0][0] >>= ctx->sprite_shift[0];
+ sprite_offset[0][1] >>= ctx->sprite_shift[0];
+ sprite_offset[1][0] >>= ctx->sprite_shift[1];
+ sprite_offset[1][1] >>= ctx->sprite_shift[1];
s->sprite_delta[0][0] = a;
s->sprite_delta[0][1] = 0;
s->sprite_delta[1][0] = 0;
@@ -367,17 +360,59 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g
} else {
int shift_y = 16 - ctx->sprite_shift[0];
int shift_c = 16 - ctx->sprite_shift[1];
+
+ if (shift_c < 0 || shift_y < 0 ||
+ FFABS(sprite_offset[0][0]) >= INT_MAX >> shift_y ||
+ FFABS(sprite_offset[1][0]) >= INT_MAX >> shift_c ||
+ FFABS(sprite_offset[0][1]) >= INT_MAX >> shift_y ||
+ FFABS(sprite_offset[1][1]) >= INT_MAX >> shift_c
+ ) {
+ avpriv_request_sample(s->avctx, "Too large sprite shift or offset");
+ goto overflow;
+ }
+
for (i = 0; i < 2; i++) {
- s->sprite_offset[0][i] <<= shift_y;
- s->sprite_offset[1][i] <<= shift_c;
- s->sprite_delta[0][i] <<= shift_y;
- s->sprite_delta[1][i] <<= shift_y;
+ sprite_offset[0][i] *= 1 << shift_y;
+ sprite_offset[1][i] *= 1 << shift_c;
+ s->sprite_delta[0][i] *= 1 << shift_y;
+ s->sprite_delta[1][i] *= 1 << shift_y;
ctx->sprite_shift[i] = 16;
+
+ }
+ for (i = 0; i < 2; i++) {
+ int64_t sd[2] = {
+ s->sprite_delta[i][0] - a * (1LL<<16),
+ s->sprite_delta[i][1] - a * (1LL<<16)
+ };
+
+ if (llabs(sprite_offset[0][i] + s->sprite_delta[i][0] * (w+16LL)) >= INT_MAX ||
+ llabs(sprite_offset[0][i] + s->sprite_delta[i][1] * (h+16LL)) >= INT_MAX ||
+ llabs(sprite_offset[0][i] + s->sprite_delta[i][0] * (w+16LL) + s->sprite_delta[i][1] * (h+16LL)) >= INT_MAX ||
+ llabs(s->sprite_delta[i][0] * (w+16LL)) >= INT_MAX ||
+ llabs(s->sprite_delta[i][1] * (w+16LL)) >= INT_MAX ||
+ llabs(sd[0]) >= INT_MAX ||
+ llabs(sd[1]) >= INT_MAX ||
+ llabs(sprite_offset[0][i] + sd[0] * (w+16LL)) >= INT_MAX ||
+ llabs(sprite_offset[0][i] + sd[1] * (h+16LL)) >= INT_MAX ||
+ llabs(sprite_offset[0][i] + sd[0] * (w+16LL) + sd[1] * (h+16LL)) >= INT_MAX
+ ) {
+ avpriv_request_sample(s->avctx, "Overflow on sprite points");
+ goto overflow;
+ }
}
s->real_sprite_warping_points = ctx->num_sprite_warping_points;
}
+ s->sprite_offset[0][0] = sprite_offset[0][0];
+ s->sprite_offset[0][1] = sprite_offset[0][1];
+ s->sprite_offset[1][0] = sprite_offset[1][0];
+ s->sprite_offset[1][1] = sprite_offset[1][1];
+
return 0;
+overflow:
+ memset(s->sprite_offset, 0, sizeof(s->sprite_offset));
+ memset(s->sprite_delta, 0, sizeof(s->sprite_delta));
+ return AVERROR_PATCHWELCOME;
}
static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) {
@@ -503,7 +538,7 @@ static inline int get_amv(Mpeg4DecContext *ctx, int n)
if (ctx->divx_version == 500 && ctx->divx_build == 413)
sum = s->sprite_offset[0][n] / (1 << (a - s->quarter_sample));
else
- sum = RSHIFT(s->sprite_offset[0][n] << s->quarter_sample, a);
+ sum = RSHIFT(s->sprite_offset[0][n] * (1 << s->quarter_sample), a);
} else {
dx = s->sprite_delta[n][0];
dy = s->sprite_delta[n][1];
@@ -2403,16 +2438,20 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
}
- if (s->pict_type == AV_PICTURE_TYPE_S &&
- (ctx->vol_sprite_usage == STATIC_SPRITE ||
- ctx->vol_sprite_usage == GMC_SPRITE)) {
- if (mpeg4_decode_sprite_trajectory(ctx, gb) < 0)
- return AVERROR_INVALIDDATA;
- if (ctx->sprite_brightness_change)
- av_log(s->avctx, AV_LOG_ERROR,
- "sprite_brightness_change not supported\n");
- if (ctx->vol_sprite_usage == STATIC_SPRITE)
- av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n");
+ if (s->pict_type == AV_PICTURE_TYPE_S) {
+ if((ctx->vol_sprite_usage == STATIC_SPRITE ||
+ ctx->vol_sprite_usage == GMC_SPRITE)) {
+ if (mpeg4_decode_sprite_trajectory(ctx, gb) < 0)
+ return AVERROR_INVALIDDATA;
+ if (ctx->sprite_brightness_change)
+ av_log(s->avctx, AV_LOG_ERROR,
+ "sprite_brightness_change not supported\n");
+ if (ctx->vol_sprite_usage == STATIC_SPRITE)
+ av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n");
+ } else {
+ memset(s->sprite_offset, 0, sizeof(s->sprite_offset));
+ memset(s->sprite_delta, 0, sizeof(s->sprite_delta));
+ }
}
if (ctx->shape != BIN_ONLY_SHAPE) {
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index 873f941237..8c39825792 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -98,7 +98,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
} else if (codec_id == AV_CODEC_ID_MP3ADU) {
avpriv_report_missing_feature(avctx,
"MP3ADU full parser");
- return AVERROR_PATCHWELCOME;
+ return 0; /* parsers must not return error codes */
}
break;
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 5e3fe7e986..79ca97a8eb 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -252,7 +252,7 @@ static inline int l3_unscale(int value, int exponent)
#endif
if (e > 31)
return 0;
- m = (m + (1 << (e - 1))) >> e;
+ m = (m + ((1U << e)>>1)) >> e;
return m;
}
@@ -1663,7 +1663,7 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
header = AV_RB32(buf);
if (header>>8 == AV_RB32("TAG")>>8) {
av_log(avctx, AV_LOG_DEBUG, "discarding ID3 tag\n");
- return buf_size;
+ return buf_size + skipped;
}
ret = avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header);
if (ret < 0) {
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 297ff78840..4af65a6c95 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2912,6 +2912,8 @@ int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t s
return AVERROR(ENOMEM);
}
+ emms_c();
+
av_fast_padded_malloc(&new_buffer, &new_buffer_size,
s->avctx->internal->byte_buffer_size + size_increase);
if (!new_buffer)
diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index 51ba435231..2d3a778ec4 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -48,8 +48,8 @@ static void gmc1_motion(MpegEncContext *s,
motion_y = s->sprite_offset[0][1];
src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy + 1));
src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy + 1));
- motion_x <<= (3 - s->sprite_warping_accuracy);
- motion_y <<= (3 - s->sprite_warping_accuracy);
+ motion_x *= 1 << (3 - s->sprite_warping_accuracy);
+ motion_y *= 1 << (3 - s->sprite_warping_accuracy);
src_x = av_clip(src_x, -16, s->width);
if (src_x == s->width)
motion_x = 0;
@@ -95,8 +95,8 @@ static void gmc1_motion(MpegEncContext *s,
motion_y = s->sprite_offset[1][1];
src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy + 1));
src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy + 1));
- motion_x <<= (3 - s->sprite_warping_accuracy);
- motion_y <<= (3 - s->sprite_warping_accuracy);
+ motion_x *= 1 << (3 - s->sprite_warping_accuracy);
+ motion_y *= 1 << (3 - s->sprite_warping_accuracy);
src_x = av_clip(src_x, -8, s->width >> 1);
if (src_x == s->width >> 1)
motion_x = 0;
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index aaadd9c073..f407910f2b 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -141,7 +141,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
if(s->msmpeg4_version==2)
cbp= get_vlc2(&s->gb, v2_intra_cbpc_vlc.table, V2_INTRA_CBPC_VLC_BITS, 1);
else
- cbp= get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1);
+ cbp= get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
if(cbp<0 || cbp>3){
av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
return -1;
@@ -170,12 +170,23 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv[0][0][1] = my;
*mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
} else {
+ int v;
if(s->msmpeg4_version==2){
s->ac_pred = get_bits1(&s->gb);
- cbp|= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors
+ v = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ if (v < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
+ return -1;
+ }
+ cbp|= v<<2;
} else{
s->ac_pred = 0;
- cbp|= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors
+ v = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ if (v < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
+ return -1;
+ }
+ cbp|= v<<2;
if(s->pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
}
*mb_type_ptr = MB_TYPE_INTRA;
diff --git a/libavcodec/msrle.c b/libavcodec/msrle.c
index 3090a910c2..33b157bc75 100644
--- a/libavcodec/msrle.c
+++ b/libavcodec/msrle.c
@@ -99,11 +99,14 @@ static int msrle_decode_frame(AVCodecContext *avctx,
return ret;
if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) {
- const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+ int size;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size);
- if (pal) {
+ if (pal && size == AVPALETTE_SIZE) {
s->frame->palette_has_changed = 1;
memcpy(s->pal, pal, AVPALETTE_SIZE);
+ } else if (pal) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
}
/* make the palette available */
memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE);
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index c640934986..cf325470b9 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -422,7 +422,13 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size,
ff_vc1_decode_blocks(v);
- ff_er_frame_end(&s->er);
+ if (v->end_mb_x == s->mb_width && s->end_mb_y == s->mb_height) {
+ ff_er_frame_end(&s->er);
+ } else {
+ av_log(v->s.avctx, AV_LOG_WARNING,
+ "disabling error correction due to block count mismatch %dx%d != %dx%d\n",
+ v->end_mb_x, s->end_mb_y, s->mb_width, s->mb_height);
+ }
ff_mpv_frame_end(s);
diff --git a/libavcodec/mss3.c b/libavcodec/mss3.c
index 01941967a5..8344bfe8a7 100644
--- a/libavcodec/mss3.c
+++ b/libavcodec/mss3.c
@@ -356,8 +356,9 @@ static int rac_get_model2_sym(RangeCoder *c, Model2 *m)
static int rac_get_model_sym(RangeCoder *c, Model *m)
{
- int prob, prob2, helper, val;
+ int val;
int end, end2;
+ unsigned prob, prob2, helper;
prob = 0;
prob2 = c->range;
diff --git a/libavcodec/mss34dsp.c b/libavcodec/mss34dsp.c
index 0397add17d..4965ac514d 100644
--- a/libavcodec/mss34dsp.c
+++ b/libavcodec/mss34dsp.c
@@ -62,30 +62,30 @@ void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma)
}
#define DCT_TEMPLATE(blk, step, SOP, shift) \
- const int t0 = -39409 * blk[7 * step] - 58980 * blk[1 * step]; \
- const int t1 = 39410 * blk[1 * step] - 58980 * blk[7 * step]; \
- const int t2 = -33410 * blk[5 * step] - 167963 * blk[3 * step]; \
- const int t3 = 33410 * blk[3 * step] - 167963 * blk[5 * step]; \
- const int t4 = blk[3 * step] + blk[7 * step]; \
- const int t5 = blk[1 * step] + blk[5 * step]; \
- const int t6 = 77062 * t4 + 51491 * t5; \
- const int t7 = 77062 * t5 - 51491 * t4; \
- const int t8 = 35470 * blk[2 * step] - 85623 * blk[6 * step]; \
- const int t9 = 35470 * blk[6 * step] + 85623 * blk[2 * step]; \
- const int tA = SOP(blk[0 * step] - blk[4 * step]); \
- const int tB = SOP(blk[0 * step] + blk[4 * step]); \
+ const unsigned t0 =-39409U * blk[7 * step] - 58980U * blk[1 * step]; \
+ const unsigned t1 = 39410U * blk[1 * step] - 58980U * blk[7 * step]; \
+ const unsigned t2 =-33410U * blk[5 * step] -167963U * blk[3 * step]; \
+ const unsigned t3 = 33410U * blk[3 * step] -167963U * blk[5 * step]; \
+ const unsigned t4 = blk[3 * step] + blk[7 * step]; \
+ const unsigned t5 = blk[1 * step] + blk[5 * step]; \
+ const unsigned t6 = 77062U * t4 + 51491U * t5; \
+ const unsigned t7 = 77062U * t5 - 51491U * t4; \
+ const unsigned t8 = 35470U * blk[2 * step] - 85623U * blk[6 * step]; \
+ const unsigned t9 = 35470U * blk[6 * step] + 85623U * blk[2 * step]; \
+ const unsigned tA = SOP(blk[0 * step] - blk[4 * step]); \
+ const unsigned tB = SOP(blk[0 * step] + blk[4 * step]); \
\
- blk[0 * step] = ( t1 + t6 + t9 + tB) >> shift; \
- blk[1 * step] = ( t3 + t7 + t8 + tA) >> shift; \
- blk[2 * step] = ( t2 + t6 - t8 + tA) >> shift; \
- blk[3 * step] = ( t0 + t7 - t9 + tB) >> shift; \
- blk[4 * step] = (-(t0 + t7) - t9 + tB) >> shift; \
- blk[5 * step] = (-(t2 + t6) - t8 + tA) >> shift; \
- blk[6 * step] = (-(t3 + t7) + t8 + tA) >> shift; \
- blk[7 * step] = (-(t1 + t6) + t9 + tB) >> shift; \
+ blk[0 * step] = (int)( t1 + t6 + t9 + tB) >> shift; \
+ blk[1 * step] = (int)( t3 + t7 + t8 + tA) >> shift; \
+ blk[2 * step] = (int)( t2 + t6 - t8 + tA) >> shift; \
+ blk[3 * step] = (int)( t0 + t7 - t9 + tB) >> shift; \
+ blk[4 * step] = (int)(-(t0 + t7) - t9 + tB) >> shift; \
+ blk[5 * step] = (int)(-(t2 + t6) - t8 + tA) >> shift; \
+ blk[6 * step] = (int)(-(t3 + t7) + t8 + tA) >> shift; \
+ blk[7 * step] = (int)(-(t1 + t6) + t9 + tB) >> shift; \
-#define SOP_ROW(a) (((a) << 16) + 0x2000)
-#define SOP_COL(a) (((a) + 32) << 16)
+#define SOP_ROW(a) (((a) * (1U << 16)) + 0x2000)
+#define SOP_COL(a) (((a) + 32) * (1U << 16))
void ff_mss34_dct_put(uint8_t *dst, int stride, int *block)
{
diff --git a/libavcodec/msvideo1.c b/libavcodec/msvideo1.c
index 891675fcb0..c53ca826cb 100644
--- a/libavcodec/msvideo1.c
+++ b/libavcodec/msvideo1.c
@@ -302,15 +302,24 @@ static int msvideo1_decode_frame(AVCodecContext *avctx,
s->buf = buf;
s->size = buf_size;
+ // Discard frame if its smaller than the minimum frame size
+ if (buf_size < (avctx->width/4) * (avctx->height/4) / 512) {
+ av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
+ return AVERROR_INVALIDDATA;
+ }
+
if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
return ret;
if (s->mode_8bit) {
- const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+ int size;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size);
- if (pal) {
+ if (pal && size == AVPALETTE_SIZE) {
memcpy(s->pal, pal, AVPALETTE_SIZE);
s->frame->palette_has_changed = 1;
+ } else if (pal) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
}
}
diff --git a/libavcodec/nellymoser.c b/libavcodec/nellymoser.c
index 0740c75a0f..d6d5b7a910 100644
--- a/libavcodec/nellymoser.c
+++ b/libavcodec/nellymoser.c
@@ -85,7 +85,7 @@ const int16_t ff_nelly_delta_table[32] = {
static inline int signed_shift(int i, int shift) {
if (shift > 0)
- return i << shift;
+ return (unsigned)i << shift;
return i >> -shift;
}
@@ -109,7 +109,7 @@ static int headroom(int *la)
return 31;
}
l = 30 - av_log2(FFABS(*la));
- *la <<= l;
+ *la *= 1<<l;
return l;
}
diff --git a/libavcodec/options.c b/libavcodec/options.c
index ea2563b571..fb23ee6ad4 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -179,6 +179,29 @@ void avcodec_free_context(AVCodecContext **pavctx)
av_freep(pavctx);
}
+static void copy_context_reset(AVCodecContext *avctx)
+{
+ int i;
+
+ av_opt_free(avctx);
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+ av_frame_free(&avctx->coded_frame);
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ av_freep(&avctx->rc_override);
+ av_freep(&avctx->intra_matrix);
+ av_freep(&avctx->inter_matrix);
+ av_freep(&avctx->extradata);
+ av_freep(&avctx->subtitle_header);
+ for (i = 0; i < avctx->nb_coded_side_data; i++)
+ av_freep(&avctx->coded_side_data[i].data);
+ av_freep(&avctx->coded_side_data);
+ avctx->subtitle_header_size = 0;
+ avctx->nb_coded_side_data = 0;
+ avctx->extradata_size = 0;
+}
+
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
{
const AVCodec *orig_codec = dest->codec;
@@ -191,12 +214,7 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
return AVERROR(EINVAL);
}
- av_opt_free(dest);
- av_freep(&dest->rc_override);
- av_freep(&dest->intra_matrix);
- av_freep(&dest->inter_matrix);
- av_freep(&dest->extradata);
- av_freep(&dest->subtitle_header);
+ copy_context_reset(dest);
memcpy(dest, src, sizeof(*dest));
av_opt_copy(dest, src);
@@ -221,10 +239,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
/* reallocate values that should be allocated separately */
dest->extradata = NULL;
+ dest->coded_side_data = NULL;
dest->intra_matrix = NULL;
dest->inter_matrix = NULL;
dest->rc_override = NULL;
dest->subtitle_header = NULL;
+ dest->nb_coded_side_data = 0;
#define alloc_and_copy_or_fail(obj, size, pad) \
if (src->obj && size > 0) { \
@@ -248,14 +268,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
return 0;
fail:
- av_freep(&dest->rc_override);
- av_freep(&dest->intra_matrix);
- av_freep(&dest->inter_matrix);
- av_freep(&dest->extradata);
- av_freep(&dest->subtitle_header);
- dest->subtitle_header_size = 0;
- dest->extradata_size = 0;
- av_opt_free(dest);
+ copy_context_reset(dest);
return AVERROR(ENOMEM);
}
diff --git a/libavcodec/opus_silk.c b/libavcodec/opus_silk.c
index 73526f9800..408e4bf43c 100644
--- a/libavcodec/opus_silk.c
+++ b/libavcodec/opus_silk.c
@@ -851,8 +851,7 @@ static inline void silk_stabilize_lsf(int16_t nlsf[16], int order, const uint16_
if (nlsf[0] < min_delta[0])
nlsf[0] = min_delta[0];
for (i = 1; i < order; i++)
- if (nlsf[i] < nlsf[i - 1] + min_delta[i])
- nlsf[i] = nlsf[i - 1] + min_delta[i];
+ nlsf[i] = FFMAX(nlsf[i], FFMIN(nlsf[i - 1] + min_delta[i], 32767));
/* push backwards to increase distance */
if (nlsf[order-1] > 32768 - min_delta[order])
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index 133d08bfa7..222c40a377 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -300,8 +300,11 @@ static int parse_object_segment(AVCodecContext *avctx,
av_fast_padded_malloc(&object->rle, &object->rle_buffer_size, rle_bitmap_len);
- if (!object->rle)
+ if (!object->rle) {
+ object->rle_data_len = 0;
+ object->rle_remaining_len = 0;
return AVERROR(ENOMEM);
+ }
memcpy(object->rle, buf, buf_size);
object->rle_data_len = buf_size;
@@ -558,12 +561,13 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
sub->rects[i]->x = ctx->presentation.objects[i].x;
sub->rects[i]->y = ctx->presentation.objects[i].y;
- sub->rects[i]->w = object->w;
- sub->rects[i]->h = object->h;
-
- sub->rects[i]->linesize[0] = object->w;
if (object->rle) {
+ sub->rects[i]->w = object->w;
+ sub->rects[i]->h = object->h;
+
+ sub->rects[i]->linesize[0] = object->w;
+
if (object->rle_remaining_len) {
av_log(avctx, AV_LOG_ERROR, "RLE data length %u is %u bytes shorter than expected\n",
object->rle_data_len, object->rle_remaining_len);
diff --git a/libavcodec/pictordec.c b/libavcodec/pictordec.c
index ff6eb7f4fc..a09ee379c0 100644
--- a/libavcodec/pictordec.c
+++ b/libavcodec/pictordec.c
@@ -77,10 +77,10 @@ static void picmemset(PicContext *s, AVFrame *frame, int value, int run,
if (*y < 0) {
*y = s->height - 1;
*plane += 1;
+ if (*plane >= s->nb_planes)
+ return;
value <<= bits_per_plane;
mask <<= bits_per_plane;
- if (*plane >= s->nb_planes)
- break;
}
}
}
@@ -142,7 +142,7 @@ static int decode_frame(AVCodecContext *avctx,
if (av_image_check_size(s->width, s->height, 0, avctx) < 0)
return -1;
- if (s->width != avctx->width && s->height != avctx->height) {
+ if (s->width != avctx->width || s->height != avctx->height) {
ret = ff_set_dimensions(avctx, s->width, s->height);
if (ret < 0)
return ret;
@@ -236,7 +236,7 @@ static int decode_frame(AVCodecContext *avctx,
}
}
- if (x < avctx->width) {
+ if (plane < s->nb_planes && x < avctx->width) {
int run = (y + 1) * avctx->width - x;
if (bits_per_plane == 8)
picmemset_8bpp(s, frame, val, run, &x, &y);
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 24318fbeaf..0bc8252465 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -437,13 +437,13 @@ static int decode_zbuf(AVBPrint *bp, const uint8_t *data,
av_bprint_init(bp, 0, -1);
while (zstream.avail_in > 0) {
- av_bprint_get_buffer(bp, 1, &buf, &buf_size);
- if (!buf_size) {
+ av_bprint_get_buffer(bp, 2, &buf, &buf_size);
+ if (buf_size < 2) {
ret = AVERROR(ENOMEM);
goto fail;
}
zstream.next_out = buf;
- zstream.avail_out = buf_size;
+ zstream.avail_out = buf_size - 1;
ret = inflate(&zstream, Z_PARTIAL_FLUSH);
if (ret != Z_OK && ret != Z_STREAM_END) {
ret = AVERROR_EXTERNAL;
@@ -559,6 +559,11 @@ static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s,
return AVERROR_INVALIDDATA;
}
s->bit_depth = bytestream2_get_byte(&s->gb);
+ if (s->bit_depth != 1 && s->bit_depth != 2 && s->bit_depth != 4 &&
+ s->bit_depth != 8 && s->bit_depth != 16) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid bit depth\n");
+ goto error;
+ }
s->color_type = bytestream2_get_byte(&s->gb);
s->compression_type = bytestream2_get_byte(&s->gb);
s->filter_type = bytestream2_get_byte(&s->gb);
@@ -572,6 +577,10 @@ static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s,
s->compression_type, s->filter_type, s->interlace_type);
return 0;
+error:
+ s->cur_w = s->cur_h = s->width = s->height = 0;
+ s->bit_depth = 8;
+ return AVERROR_INVALIDDATA;
}
static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s)
@@ -602,8 +611,9 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s,
}
if (!(s->state & PNG_IDAT)) {
/* init image info */
- avctx->width = s->width;
- avctx->height = s->height;
+ ret = ff_set_dimensions(avctx, s->width, s->height);
+ if (ret < 0)
+ return ret;
s->channels = ff_png_get_nb_channels(s->color_type);
s->bits_per_pixel = s->bit_depth * s->channels;
@@ -772,17 +782,28 @@ static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s,
{
int v, i;
+ if (!(s->state & PNG_IHDR)) {
+ av_log(avctx, AV_LOG_ERROR, "trns before IHDR\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (s->state & PNG_IDAT) {
+ av_log(avctx, AV_LOG_ERROR, "trns after IDAT\n");
+ return AVERROR_INVALIDDATA;
+ }
+
if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
if (length > 256 || !(s->state & PNG_PLTE))
return AVERROR_INVALIDDATA;
for (i = 0; i < length; i++) {
- v = bytestream2_get_byte(&s->gb);
+ unsigned v = bytestream2_get_byte(&s->gb);
s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
}
} else if (s->color_type == PNG_COLOR_TYPE_GRAY || s->color_type == PNG_COLOR_TYPE_RGB) {
if ((s->color_type == PNG_COLOR_TYPE_GRAY && length != 2) ||
- (s->color_type == PNG_COLOR_TYPE_RGB && length != 6))
+ (s->color_type == PNG_COLOR_TYPE_RGB && length != 6) ||
+ s->bit_depth == 1)
return AVERROR_INVALIDDATA;
for (i = 0; i < length / 2; i++) {
@@ -1241,6 +1262,8 @@ exit_loop:
size_t raw_bpp = s->bpp - byte_depth;
unsigned x, y;
+ av_assert0(s->bit_depth > 1);
+
for (y = 0; y < s->height; ++y) {
uint8_t *row = &s->image_buf[s->image_linesize * y];
diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c
index d4261a4530..4e2045d2b3 100644
--- a/libavcodec/pnmdec.c
+++ b/libavcodec/pnmdec.c
@@ -43,7 +43,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
int buf_size = avpkt->size;
PNMContext * const s = avctx->priv_data;
AVFrame * const p = data;
- int i, j, n, linesize, h, upgrade = 0, is_mono = 0;
+ int i, j, k, n, linesize, h, upgrade = 0, is_mono = 0;
unsigned char *ptr;
int components, sample_len, ret;
@@ -143,10 +143,14 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
v = (*s->bytestream++)&1;
} else {
/* read a sequence of digits */
- do {
+ for (k = 0; k < 5 && c <= 9; k += 1) {
v = 10*v + c;
c = (*s->bytestream++) - '0';
- } while (c <= 9);
+ }
+ if (v > s->maxval) {
+ av_log(avctx, AV_LOG_ERROR, "value %d larger than maxval %d\n", v, s->maxval);
+ return AVERROR_INVALIDDATA;
+ }
}
if (sample_len == 16) {
((uint16_t*)ptr)[j] = (((1<<sample_len)-1)*v + (s->maxval>>1))/s->maxval;
diff --git a/libavcodec/ppc/pixblockdsp.c b/libavcodec/ppc/pixblockdsp.c
index 84aa562bb6..f3a5050469 100644
--- a/libavcodec/ppc/pixblockdsp.c
+++ b/libavcodec/ppc/pixblockdsp.c
@@ -67,10 +67,10 @@ static void get_pixels_altivec(int16_t *restrict block, const uint8_t *pixels,
ptrdiff_t line_size)
{
int i;
- vec_u8 perm = vec_lvsl(0, pixels);
const vec_u8 zero = (const vec_u8)vec_splat_u8(0);
for (i = 0; i < 8; i++) {
+ vec_u8 perm = vec_lvsl(0, pixels);
/* Read potentially unaligned pixels.
* We're reading 16 pixels, and actually only want 8,
* but we simply ignore the extras. */
@@ -157,8 +157,7 @@ static void diff_pixels_altivec(int16_t *restrict block, const uint8_t *s1,
const uint8_t *s2, int stride)
{
int i;
- vec_u8 perm1 = vec_lvsl(0, s1);
- vec_u8 perm2 = vec_lvsl(0, s2);
+ vec_u8 perm;
const vec_u8 zero = (const vec_u8)vec_splat_u8(0);
vec_s16 shorts1, shorts2;
@@ -166,17 +165,19 @@ static void diff_pixels_altivec(int16_t *restrict block, const uint8_t *s1,
/* Read potentially unaligned pixels.
* We're reading 16 pixels, and actually only want 8,
* but we simply ignore the extras. */
+ perm = vec_lvsl(0, s1);
vec_u8 pixl = vec_ld(0, s1);
vec_u8 pixr = vec_ld(15, s1);
- vec_u8 bytes = vec_perm(pixl, pixr, perm1);
+ vec_u8 bytes = vec_perm(pixl, pixr, perm);
// Convert the bytes into shorts.
shorts1 = (vec_s16)vec_mergeh(zero, bytes);
// Do the same for the second block of pixels.
+ perm = vec_lvsl(0, s2);
pixl = vec_ld(0, s2);
pixr = vec_ld(15, s2);
- bytes = vec_perm(pixl, pixr, perm2);
+ bytes = vec_perm(pixl, pixr, perm);
// Convert the bytes into shorts.
shorts2 = (vec_s16)vec_mergeh(zero, bytes);
@@ -197,17 +198,19 @@ static void diff_pixels_altivec(int16_t *restrict block, const uint8_t *s1,
/* Read potentially unaligned pixels.
* We're reading 16 pixels, and actually only want 8,
* but we simply ignore the extras. */
+ perm = vec_lvsl(0, s1);
pixl = vec_ld(0, s1);
pixr = vec_ld(15, s1);
- bytes = vec_perm(pixl, pixr, perm1);
+ bytes = vec_perm(pixl, pixr, perm);
// Convert the bytes into shorts.
shorts1 = (vec_s16)vec_mergeh(zero, bytes);
// Do the same for the second block of pixels.
+ perm = vec_lvsl(0, s2);
pixl = vec_ld(0, s2);
pixr = vec_ld(15, s2);
- bytes = vec_perm(pixl, pixr, perm2);
+ bytes = vec_perm(pixl, pixr, perm);
// Convert the bytes into shorts.
shorts2 = (vec_s16)vec_mergeh(zero, bytes);
diff --git a/libavcodec/proresdec_lgpl.c b/libavcodec/proresdec_lgpl.c
index 467a423f23..bc5bdb5a4d 100644
--- a/libavcodec/proresdec_lgpl.c
+++ b/libavcodec/proresdec_lgpl.c
@@ -625,7 +625,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata)
/* if V or alpha component size is negative that means that previous
component sizes are too large */
- if (v_data_size < 0 || a_data_size < 0 || hdr_size < 6) {
+ if (v_data_size < 0 || a_data_size < 0 || hdr_size < 6 || coff[3] > slice_data_size) {
av_log(avctx, AV_LOG_ERROR, "invalid data size\n");
return AVERROR_INVALIDDATA;
}
diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c
index 9eaf9b8054..9bfecc3a31 100644
--- a/libavcodec/qpeg.c
+++ b/libavcodec/qpeg.c
@@ -260,7 +260,8 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame * const ref = a->ref;
uint8_t* outdata;
int delta, ret;
- const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+ int pal_size;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size);
if (avpkt->size < 0x86) {
av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
@@ -287,9 +288,11 @@ static int decode_frame(AVCodecContext *avctx,
}
/* make the palette available on the way out */
- if (pal) {
+ if (pal && pal_size == AVPALETTE_SIZE) {
p->palette_has_changed = 1;
memcpy(a->pal, pal, AVPALETTE_SIZE);
+ } else if (pal) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size);
}
memcpy(p->data[1], a->pal, AVPALETTE_SIZE);
diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index 3f482f4453..5745afc517 100644
--- a/libavcodec/qtrle.c
+++ b/libavcodec/qtrle.c
@@ -506,11 +506,14 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
}
if(has_palette) {
- const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+ int size;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size);
- if (pal) {
+ if (pal && size == AVPALETTE_SIZE) {
s->frame->palette_has_changed = 1;
memcpy(s->pal, pal, AVPALETTE_SIZE);
+ } else if (pal) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
}
/* make the palette available on the way out */
diff --git a/libavcodec/ra144.c b/libavcodec/ra144.c
index 696a49e7ab..cfe5aea7dc 100644
--- a/libavcodec/ra144.c
+++ b/libavcodec/ra144.c
@@ -1598,7 +1598,7 @@ void ff_eval_coefs(int *coefs, const int *refl)
int i, j;
for (i=0; i < LPC_ORDER; i++) {
- b1[i] = refl[i] << 4;
+ b1[i] = refl[i] * 16;
for (j=0; j < i; j++)
b1[j] = ((refl[i] * b2[i-j-1]) >> 12) + b2[j];
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 193a88fd33..fbdf4810fa 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -383,8 +383,13 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
}
if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
+ int pal_size;
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE,
- NULL);
+ &pal_size);
+ if (pal && pal_size != AVPALETTE_SIZE) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size);
+ pal = NULL;
+ }
if (pal) {
av_buffer_unref(&context->palette);
diff --git a/libavcodec/rscc.c b/libavcodec/rscc.c
index 0c3e81845d..78a8bcea0b 100644
--- a/libavcodec/rscc.c
+++ b/libavcodec/rscc.c
@@ -184,6 +184,12 @@ static int rscc_decode_frame(AVCodecContext *avctx, void *data,
ctx->tiles[i].y = bytestream2_get_le16(gbc);
ctx->tiles[i].h = bytestream2_get_le16(gbc);
+ if (pixel_size + ctx->tiles[i].w * (int64_t)ctx->tiles[i].h * 4 > INT_MAX) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid tile dimensions\n");
+ ret = AVERROR_INVALIDDATA;
+ goto end;
+ }
+
pixel_size += ctx->tiles[i].w * ctx->tiles[i].h * 4;
ff_dlog(avctx, "tile %d orig(%d,%d) %dx%d.\n", i,
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index c2e84a3b57..ac7b36bb2f 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1585,10 +1585,13 @@ int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecConte
return ff_mpeg_update_thread_context(dst, src);
}
-static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n)
+static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n, int slice_count, int buf_size)
{
- if(avctx->slice_count) return avctx->slice_offset[n];
- else return AV_RL32(buf + n*8 - 4) == 1 ? AV_RL32(buf + n*8) : AV_RB32(buf + n*8);
+ if (n < slice_count) {
+ if(avctx->slice_count) return avctx->slice_offset[n];
+ else return AV_RL32(buf + n*8 - 4) == 1 ? AV_RL32(buf + n*8) : AV_RB32(buf + n*8);
+ } else
+ return buf_size;
}
static int finish_frame(AVCodecContext *avctx, AVFrame *pict)
@@ -1627,7 +1630,7 @@ static AVRational update_sar(int old_w, int old_h, AVRational sar, int new_w, in
if (!sar.num)
sar = (AVRational){1, 1};
- sar = av_mul_q(sar, (AVRational){new_h * old_w, new_w * old_h});
+ sar = av_mul_q(sar, av_mul_q((AVRational){new_h, new_w}, (AVRational){old_w, old_h}));
return sar;
}
@@ -1646,6 +1649,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
const uint8_t *slices_hdr = NULL;
int last = 0;
int faulty_b = 0;
+ int offset;
/* no supplementary picture */
if (buf_size == 0) {
@@ -1668,13 +1672,13 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
}else
slice_count = avctx->slice_count;
+ offset = get_slice_offset(avctx, slices_hdr, 0, slice_count, buf_size);
//parse first slice header to check whether this frame can be decoded
- if(get_slice_offset(avctx, slices_hdr, 0) < 0 ||
- get_slice_offset(avctx, slices_hdr, 0) > buf_size){
+ if(offset < 0 || offset > buf_size){
av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n");
return AVERROR_INVALIDDATA;
}
- init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, 0), (buf_size-get_slice_offset(avctx, slices_hdr, 0))*8);
+ init_get_bits(&s->gb, buf+offset, (buf_size-offset)*8);
if(r->parse_slice_header(r, &r->s.gb, &si) < 0 || si.start){
av_log(avctx, AV_LOG_ERROR, "First slice header is incorrect\n");
return AVERROR_INVALIDDATA;
@@ -1777,40 +1781,32 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
return AVERROR_INVALIDDATA;
for(i = 0; i < slice_count; i++){
- int offset = get_slice_offset(avctx, slices_hdr, i);
+ int offset = get_slice_offset(avctx, slices_hdr, i , slice_count, buf_size);
+ int offset1 = get_slice_offset(avctx, slices_hdr, i+1, slice_count, buf_size);
int size;
- if(i+1 == slice_count)
- size = buf_size - offset;
- else
- size = get_slice_offset(avctx, slices_hdr, i+1) - offset;
- if(offset < 0 || offset > buf_size){
+ if(offset < 0 || offset > offset1 || offset1 > buf_size){
av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n");
break;
}
+ size = offset1 - offset;
r->si.end = s->mb_width * s->mb_height;
s->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start;
if(i+1 < slice_count){
- if (get_slice_offset(avctx, slices_hdr, i+1) < 0 ||
- get_slice_offset(avctx, slices_hdr, i+1) > buf_size) {
+ int offset2 = get_slice_offset(avctx, slices_hdr, i+2, slice_count, buf_size);
+ if (offset2 < offset1 || offset2 > buf_size) {
av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n");
break;
}
- init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, i+1), (buf_size-get_slice_offset(avctx, slices_hdr, i+1))*8);
+ init_get_bits(&s->gb, buf+offset1, (buf_size-offset1)*8);
if(r->parse_slice_header(r, &r->s.gb, &si) < 0){
- if(i+2 < slice_count)
- size = get_slice_offset(avctx, slices_hdr, i+2) - offset;
- else
- size = buf_size - offset;
+ size = offset2 - offset;
}else
r->si.end = si.start;
}
- if (size < 0 || size > buf_size - offset) {
- av_log(avctx, AV_LOG_ERROR, "Slice size is invalid\n");
- break;
- }
+ av_assert0 (size >= 0 && size <= buf_size - offset);
last = rv34_decode_slice(r, r->si.end, buf + offset, size);
if(last)
break;
diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c
index 3ff1554d3c..e4c8400268 100644
--- a/libavcodec/rv40.c
+++ b/libavcodec/rv40.c
@@ -109,6 +109,8 @@ static int get_dimension(GetBitContext *gb, const int *dim)
val = dim[get_bits1(gb) - val];
if(!val){
do{
+ if (get_bits_left(gb) < 8)
+ return AVERROR_INVALIDDATA;
t = get_bits(gb, 8);
val += t << 2;
}while(t == 0xFF);
@@ -187,7 +189,7 @@ static int rv40_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t
A = ptr[-r->intra_types_stride + 1]; // it won't be used for the last coefficient in a row
B = ptr[-r->intra_types_stride];
C = ptr[-1];
- pattern = A + (B << 4) + (C << 8);
+ pattern = A + B * (1 << 4) + C * (1 << 8);
for(k = 0; k < MODE2_PATTERNS_NUM; k++)
if(pattern == rv40_aic_table_index[k])
break;
diff --git a/libavcodec/rv40dsp.c b/libavcodec/rv40dsp.c
index 19b0e93696..95ba0a9259 100644
--- a/libavcodec/rv40dsp.c
+++ b/libavcodec/rv40dsp.c
@@ -449,7 +449,7 @@ static av_always_inline void rv40_weak_loop_filter(uint8_t *src,
if (u > 3 - (filter_p1 && filter_q1))
continue;
- t <<= 2;
+ t *= 1 << 2;
if (filter_p1 && filter_q1)
t += src[-2*step] - src[1*step];
diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
index ccfb5913a0..a68ac79f2c 100644
--- a/libavcodec/s302m.c
+++ b/libavcodec/s302m.c
@@ -120,10 +120,10 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
if (avctx->bits_per_raw_sample == 24) {
uint32_t *o = (uint32_t *)frame->data[0];
for (; buf_size > 6; buf_size -= 7) {
- *o++ = (ff_reverse[buf[2]] << 24) |
+ *o++ = ((unsigned)ff_reverse[buf[2]] << 24) |
(ff_reverse[buf[1]] << 16) |
(ff_reverse[buf[0]] << 8);
- *o++ = (ff_reverse[buf[6] & 0xf0] << 28) |
+ *o++ = ((unsigned)ff_reverse[buf[6] & 0xf0] << 28) |
(ff_reverse[buf[5]] << 20) |
(ff_reverse[buf[4]] << 12) |
(ff_reverse[buf[3] & 0x0f] << 4);
@@ -142,10 +142,10 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
} else if (avctx->bits_per_raw_sample == 20) {
uint32_t *o = (uint32_t *)frame->data[0];
for (; buf_size > 5; buf_size -= 6) {
- *o++ = (ff_reverse[buf[2] & 0xf0] << 28) |
+ *o++ = ((unsigned)ff_reverse[buf[2] & 0xf0] << 28) |
(ff_reverse[buf[1]] << 20) |
(ff_reverse[buf[0]] << 12);
- *o++ = (ff_reverse[buf[5] & 0xf0] << 28) |
+ *o++ = ((unsigned)ff_reverse[buf[5] & 0xf0] << 28) |
(ff_reverse[buf[4]] << 20) |
(ff_reverse[buf[3]] << 12);
buf += 6;
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 0f5be96eb7..32f808beb4 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -156,8 +156,11 @@ static int allocate_buffers(ShortenContext *s)
static inline unsigned int get_uint(ShortenContext *s, int k)
{
- if (s->version != 0)
+ if (s->version != 0) {
k = get_ur_golomb_shorten(&s->gb, ULONGSIZE);
+ if (k > 31U)
+ return AVERROR_INVALIDDATA;
+ }
return get_ur_golomb_shorten(&s->gb, k);
}
diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 4014e8d04c..8dc474c42e 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -131,8 +131,12 @@ static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t pref
/**
* Decode header tree
*/
-static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx)
+static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx, int length)
{
+ if(length > 500) { // Larger length can cause segmentation faults due to too deep recursion.
+ av_log(NULL, AV_LOG_ERROR, "length too long\n");
+ return AVERROR_INVALIDDATA;
+ }
if (hc->current + 1 >= hc->length) {
av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
return AVERROR_INVALIDDATA;
@@ -161,12 +165,12 @@ static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx
int r = 0, r_new, t;
t = hc->current++;
- r = smacker_decode_bigtree(gb, hc, ctx);
+ r = smacker_decode_bigtree(gb, hc, ctx, length + 1);
if(r < 0)
return r;
hc->values[t] = SMK_NODE | r;
r++;
- r_new = smacker_decode_bigtree(gb, hc, ctx);
+ r_new = smacker_decode_bigtree(gb, hc, ctx, length + 1);
if (r_new < 0)
return r_new;
return r + r_new;
@@ -277,7 +281,7 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int
goto error;
}
- if (smacker_decode_bigtree(gb, &huff, &ctx) < 0)
+ if (smacker_decode_bigtree(gb, &huff, &ctx, 0) < 0)
err = -1;
skip_bits1(gb);
if(ctx.last[0] == -1) ctx.last[0] = huff.current++;
diff --git a/libavcodec/smvjpegdec.c b/libavcodec/smvjpegdec.c
index 9057e86161..e319e5781b 100644
--- a/libavcodec/smvjpegdec.c
+++ b/libavcodec/smvjpegdec.c
@@ -152,6 +152,10 @@ static int smvjpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_siz
cur_frame = avpkt->pts % s->frames_per_jpeg;
+ /* cur_frame is later used to calculate the buffer offset, so it mustn't be negative */
+ if (cur_frame < 0)
+ cur_frame += s->frames_per_jpeg;
+
/* Are we at the start of a block? */
if (!cur_frame) {
av_frame_unref(mjpeg_data);
diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c
index 042aecbbeb..022e9693c7 100644
--- a/libavcodec/snowdec.c
+++ b/libavcodec/snowdec.c
@@ -384,6 +384,10 @@ static int decode_header(SnowContext *s){
av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_count %d too large for size\n", s->spatial_decomposition_count);
return AVERROR_INVALIDDATA;
}
+ if (s->avctx->width > 65536-4) {
+ av_log(s->avctx, AV_LOG_ERROR, "Width %d is too large\n", s->avctx->width);
+ return AVERROR_INVALIDDATA;
+ }
s->qlog += get_symbol(&s->c, s->header_state, 1);
@@ -395,6 +399,11 @@ static int decode_header(SnowContext *s){
s->block_max_depth= 0;
return AVERROR_INVALIDDATA;
}
+ if (FFABS(s->qbias) > 127) {
+ av_log(s->avctx, AV_LOG_ERROR, "qbias %d is too large\n", s->qbias);
+ s->qbias = 0;
+ return AVERROR_INVALIDDATA;
+ }
return 0;
}
diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index 542dd35795..d830d7ca6f 100644
--- a/libavcodec/srtdec.c
+++ b/libavcodec/srtdec.c
@@ -38,13 +38,13 @@ static void srt_to_ass(AVCodecContext *avctx, AVBPrint *dst,
/* text rectangle defined, write the text at the center of the rectangle */
const int cx = x1 + (x2 - x1)/2;
const int cy = y1 + (y2 - y1)/2;
- const int scaled_x = cx * ASS_DEFAULT_PLAYRESX / 720;
- const int scaled_y = cy * ASS_DEFAULT_PLAYRESY / 480;
+ const int scaled_x = cx * (int64_t)ASS_DEFAULT_PLAYRESX / 720;
+ const int scaled_y = cy * (int64_t)ASS_DEFAULT_PLAYRESY / 480;
av_bprintf(dst, "{\\an5}{\\pos(%d,%d)}", scaled_x, scaled_y);
} else {
/* only the top left corner, assume the text starts in that corner */
- const int scaled_x = x1 * ASS_DEFAULT_PLAYRESX / 720;
- const int scaled_y = y1 * ASS_DEFAULT_PLAYRESY / 480;
+ const int scaled_x = x1 * (int64_t)ASS_DEFAULT_PLAYRESX / 720;
+ const int scaled_y = y1 * (int64_t)ASS_DEFAULT_PLAYRESY / 480;
av_bprintf(dst, "{\\an1}{\\pos(%d,%d)}", scaled_x, scaled_y);
}
}
diff --git a/libavcodec/sunrast.c b/libavcodec/sunrast.c
index 25e11f6cd2..0af5626e35 100644
--- a/libavcodec/sunrast.c
+++ b/libavcodec/sunrast.c
@@ -168,7 +168,7 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
}
} else {
for (y = 0; y < h; y++) {
- if (buf_end - buf < len)
+ if (buf_end - buf < alen)
break;
memcpy(ptr, buf, len);
ptr += stride;
diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index 57205c6ad1..e05cab5a04 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -166,7 +166,7 @@ static int svq3_decode_end(AVCodecContext *avctx);
void ff_svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
{
- const int qmul = svq3_dequant_coeff[qp];
+ const unsigned qmul = svq3_dequant_coeff[qp];
#define stride 16
int i;
int temp[16];
@@ -191,10 +191,10 @@ void ff_svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
- output[stride * 0 + offset] = (z0 + z3) * qmul + 0x80000 >> 20;
- output[stride * 2 + offset] = (z1 + z2) * qmul + 0x80000 >> 20;
- output[stride * 8 + offset] = (z1 - z2) * qmul + 0x80000 >> 20;
- output[stride * 10 + offset] = (z0 - z3) * qmul + 0x80000 >> 20;
+ output[stride * 0 + offset] = (int)((z0 + z3) * qmul + 0x80000) >> 20;
+ output[stride * 2 + offset] = (int)((z1 + z2) * qmul + 0x80000) >> 20;
+ output[stride * 8 + offset] = (int)((z1 - z2) * qmul + 0x80000) >> 20;
+ output[stride * 10 + offset] = (int)((z0 - z3) * qmul + 0x80000) >> 20;
}
}
#undef stride
@@ -206,7 +206,7 @@ void ff_svq3_add_idct_c(uint8_t *dst, int16_t *block,
int i;
if (dc) {
- dc = 13 * 13 * (dc == 1 ? 1538 * block[0]
+ dc = 13 * 13 * (dc == 1 ? 1538U* block[0]
: qmul * (block[0] >> 3) / 2);
block[0] = 0;
}
@@ -224,16 +224,16 @@ void ff_svq3_add_idct_c(uint8_t *dst, int16_t *block,
}
for (i = 0; i < 4; i++) {
- const int z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
- const int z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
- const int z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
- const int z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
+ const unsigned z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
+ const unsigned z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
+ const unsigned z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
+ const unsigned z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
const int rr = (dc + 0x80000);
- dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((z0 + z3) * qmul + rr >> 20));
- dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((z1 + z2) * qmul + rr >> 20));
- dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((z1 - z2) * qmul + rr >> 20));
- dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((z0 - z3) * qmul + rr >> 20));
+ dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((int)((z0 + z3) * qmul + rr) >> 20));
+ dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((int)((z1 + z2) * qmul + rr) >> 20));
+ dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((int)((z1 - z2) * qmul + rr) >> 20));
+ dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((int)((z0 - z3) * qmul + rr) >> 20));
}
memset(block, 0, 16 * sizeof(int16_t));
@@ -397,8 +397,8 @@ static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
if (mode != PREDICT_MODE) {
pred_motion(h, sl, k, part_width >> 2, dir, 1, &mx, &my);
} else {
- mx = s->next_pic->motion_val[0][b_xy][0] << 1;
- my = s->next_pic->motion_val[0][b_xy][1] << 1;
+ mx = s->next_pic->motion_val[0][b_xy][0] * 2;
+ my = s->next_pic->motion_val[0][b_xy][1] * 2;
if (dir == 0) {
mx = mx * h->frame_num_offset /
@@ -435,8 +435,8 @@ static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
int fx, fy;
mx = (mx + 1 >> 1) + dx;
my = (my + 1 >> 1) + dy;
- fx = (unsigned)(mx + 0x3000) / 3 - 0x1000;
- fy = (unsigned)(my + 0x3000) / 3 - 0x1000;
+ fx = (unsigned)(mx + 0x30000) / 3 - 0x10000;
+ fy = (unsigned)(my + 0x30000) / 3 - 0x10000;
dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
svq3_mc_dir_part(s, x, y, part_width, part_height,
@@ -444,8 +444,8 @@ static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
mx += mx;
my += my;
} else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
- mx = (unsigned)(mx + 1 + 0x3000) / 3 + dx - 0x1000;
- my = (unsigned)(my + 1 + 0x3000) / 3 + dy - 0x1000;
+ mx = (unsigned)(mx + 1 + 0x30000) / 3 + dx - 0x10000;
+ my = (unsigned)(my + 1 + 0x30000) / 3 + dy - 0x10000;
dxy = (mx & 1) + 2 * (my & 1);
svq3_mc_dir_part(s, x, y, part_width, part_height,
@@ -453,8 +453,8 @@ static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
mx *= 3;
my *= 3;
} else {
- mx = (unsigned)(mx + 3 + 0x6000) / 6 + dx - 0x1000;
- my = (unsigned)(my + 3 + 0x6000) / 6 + dy - 0x1000;
+ mx = (unsigned)(mx + 3 + 0x60000) / 6 + dx - 0x10000;
+ my = (unsigned)(my + 3 + 0x60000) / 6 + dy - 0x10000;
svq3_mc_dir_part(s, x, y, part_width, part_height,
mx, my, 0, 0, dir, avg);
diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c
index 001086bc74..43b3c92077 100644
--- a/libavcodec/takdec.c
+++ b/libavcodec/takdec.c
@@ -422,19 +422,19 @@ static int decode_subframe(TAKDecContext *s, int32_t *decoded,
s->predictors[0] = get_sbits(gb, 10);
s->predictors[1] = get_sbits(gb, 10);
- s->predictors[2] = get_sbits(gb, size) << (10 - size);
- s->predictors[3] = get_sbits(gb, size) << (10 - size);
+ s->predictors[2] = get_sbits(gb, size) * (1 << (10 - size));
+ s->predictors[3] = get_sbits(gb, size) * (1 << (10 - size));
if (filter_order > 4) {
int tmp = size - get_bits1(gb);
for (i = 4; i < filter_order; i++) {
if (!(i & 3))
x = tmp - get_bits(gb, 2);
- s->predictors[i] = get_sbits(gb, x) << (10 - size);
+ s->predictors[i] = get_sbits(gb, x) * (1 << (10 - size));
}
}
- tfilter[0] = s->predictors[0] << 6;
+ tfilter[0] = s->predictors[0] * 64;
for (i = 1; i < filter_order; i++) {
int32_t *p1 = &tfilter[0];
int32_t *p2 = &tfilter[i - 1];
@@ -446,7 +446,7 @@ static int decode_subframe(TAKDecContext *s, int32_t *decoded,
p2--;
}
- tfilter[i] = s->predictors[i] << 6;
+ tfilter[i] = s->predictors[i] * 64;
}
x = 1 << (32 - (15 - filter_quant));
@@ -480,7 +480,7 @@ static int decode_subframe(TAKDecContext *s, int32_t *decoded,
s->residues[i + j + 1] * s->filter[j + 1] +
s->residues[i + j ] * s->filter[j ];
}
- v = (av_clip_intp2(v >> filter_quant, 13) << dshift) - *decoded;
+ v = (av_clip_intp2(v >> filter_quant, 13) * (1 << dshift)) - *decoded;
*decoded++ = v;
s->residues[filter_order + i] = v >> dshift;
}
@@ -893,7 +893,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
for (chan = 0; chan < avctx->channels; chan++) {
int32_t *samples = (int32_t *)frame->extended_data[chan];
for (i = 0; i < s->nb_samples; i++)
- samples[i] <<= 8;
+ samples[i] *= 1 << 8;
}
break;
}
diff --git a/libavcodec/targa_y216dec.c b/libavcodec/targa_y216dec.c
index 21b3d35d67..443d48a92f 100644
--- a/libavcodec/targa_y216dec.c
+++ b/libavcodec/targa_y216dec.c
@@ -35,7 +35,8 @@ static int y216_decode_frame(AVCodecContext *avctx, void *data,
{
AVFrame *pic = data;
const uint16_t *src = (uint16_t *)avpkt->data;
- uint16_t *y, *u, *v, aligned_width = FFALIGN(avctx->width, 4);
+ uint16_t *y, *u, *v;
+ int aligned_width = FFALIGN(avctx->width, 4);
int i, j, ret;
if (avpkt->size < 4 * avctx->height * aligned_width) {
diff --git a/libavcodec/texturedsp.c b/libavcodec/texturedsp.c
index c5e6cc6270..9283f2973b 100644
--- a/libavcodec/texturedsp.c
+++ b/libavcodec/texturedsp.c
@@ -35,7 +35,7 @@
#define RGBA(r, g, b, a) (((uint8_t)(r) << 0) | \
((uint8_t)(g) << 8) | \
((uint8_t)(b) << 16) | \
- ((uint8_t)(a) << 24))
+ ((unsigned)(uint8_t)(a) << 24))
static av_always_inline void extract_color(uint32_t colors[4],
uint16_t color0,
@@ -158,7 +158,7 @@ static inline void dxt3_block_internal(uint8_t *dst, ptrdiff_t stride,
for (x = 0; x < 4; x++) {
uint8_t alpha = alpha_values[x];
- uint32_t pixel = colors[code & 3] | (alpha << 24);
+ uint32_t pixel = colors[code & 3] | ((unsigned)alpha << 24);
code >>= 2;
AV_WL32(dst + x * 4, pixel);
@@ -291,7 +291,7 @@ static inline void dxt5_block_internal(uint8_t *dst, ptrdiff_t stride,
}
}
}
- pixel = colors[code & 3] | (alpha << 24);
+ pixel = colors[code & 3] | ((unsigned)alpha << 24);
code >>= 2;
AV_WL32(dst + x * 4, pixel);
}
diff --git a/libavcodec/tiertexseqv.c b/libavcodec/tiertexseqv.c
index df12ee3809..f86ae2aac1 100644
--- a/libavcodec/tiertexseqv.c
+++ b/libavcodec/tiertexseqv.c
@@ -213,10 +213,15 @@ static int seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int
static av_cold int seqvideo_decode_init(AVCodecContext *avctx)
{
SeqVideoContext *seq = avctx->priv_data;
+ int ret;
seq->avctx = avctx;
avctx->pix_fmt = AV_PIX_FMT_PAL8;
+ ret = ff_set_dimensions(avctx, 256, 128);
+ if (ret < 0)
+ return ret;
+
seq->frame = av_frame_alloc();
if (!seq->frame)
return AVERROR(ENOMEM);
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 4be587d569..dac406862d 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -408,7 +408,7 @@ static int tiff_unpack_lzma(TiffContext *s, AVFrame *p, uint8_t *dst, int stride
const uint8_t *src, int size, int width, int lines,
int strip_start, int is_yuv)
{
- uint64_t outlen = width * lines;
+ uint64_t outlen = width * (uint64_t)lines;
int ret, line;
uint8_t *buf = av_malloc(outlen);
if (!buf)
@@ -904,6 +904,11 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
break;
case TIFF_STRIP_OFFS:
if (count == 1) {
+ if (value > INT_MAX) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "strippos %u too large\n", value);
+ return AVERROR_INVALIDDATA;
+ }
s->strippos = 0;
s->stripoff = value;
} else
@@ -915,6 +920,11 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
break;
case TIFF_STRIP_SIZE:
if (count == 1) {
+ if (value > INT_MAX) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "stripsize %u too large\n", value);
+ return AVERROR_INVALIDDATA;
+ }
s->stripsizesoff = 0;
s->stripsize = value;
s->strips = 1;
@@ -1008,6 +1018,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
s->subsampling[i] = ff_tget(&s->gb, type, s->le);
if (s->subsampling[i] <= 0) {
av_log(s->avctx, AV_LOG_ERROR, "subsampling %d is invalid\n", s->subsampling[i]);
+ s->subsampling[i] = 1;
return AVERROR_INVALIDDATA;
}
}
@@ -1035,6 +1046,10 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
ADD_METADATA(count, "ModelTiepointTag", NULL);
break;
case TIFF_GEO_KEY_DIRECTORY:
+ if (s->geotag_count) {
+ avpriv_request_sample(s->avctx, "Multiple geo key directories\n");
+ return AVERROR_INVALIDDATA;
+ }
ADD_METADATA(1, "GeoTIFF_Version", NULL);
ADD_METADATA(2, "GeoTIFF_Key_Revision", ".");
s->geotag_count = ff_tget_short(&s->gb, s->le);
@@ -1042,7 +1057,8 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
s->geotag_count = count / 4 - 1;
av_log(s->avctx, AV_LOG_WARNING, "GeoTIFF key directory buffer shorter than specified\n");
}
- if (bytestream2_get_bytes_left(&s->gb) < s->geotag_count * sizeof(int16_t) * 4) {
+ if ( bytestream2_get_bytes_left(&s->gb) < s->geotag_count * sizeof(int16_t) * 4
+ || s->geotag_count == 0) {
s->geotag_count = 0;
return -1;
}
diff --git a/libavcodec/truemotion1.c b/libavcodec/truemotion1.c
index da843c4440..28dccaae47 100644
--- a/libavcodec/truemotion1.c
+++ b/libavcodec/truemotion1.c
@@ -177,10 +177,10 @@ static int make_ydt15_entry(int p1, int p2, int16_t *ydt)
int lo, hi;
lo = ydt[p1];
- lo += (lo << 5) + (lo << 10);
+ lo += (lo * 32) + (lo * 1024);
hi = ydt[p2];
- hi += (hi << 5) + (hi << 10);
- return (lo + (hi << 16)) << 1;
+ hi += (hi * 32) + (hi * 1024);
+ return (lo + (hi * (1U << 16))) * 2;
}
static int make_cdt15_entry(int p1, int p2, int16_t *cdt)
@@ -188,9 +188,9 @@ static int make_cdt15_entry(int p1, int p2, int16_t *cdt)
int r, b, lo;
b = cdt[p2];
- r = cdt[p1] << 10;
+ r = cdt[p1] * 1024;
lo = b + r;
- return (lo + (lo << 16)) << 1;
+ return (lo + (lo * (1U << 16))) * 2;
}
#if HAVE_BIGENDIAN
diff --git a/libavcodec/tscc.c b/libavcodec/tscc.c
index 8c5ec68cf4..3dd476aee5 100644
--- a/libavcodec/tscc.c
+++ b/libavcodec/tscc.c
@@ -99,11 +99,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
/* make the palette available on the way out */
if (c->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
- const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+ int size;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size);
- if (pal) {
+ if (pal && size == AVPALETTE_SIZE) {
frame->palette_has_changed = 1;
memcpy(c->pal, pal, AVPALETTE_SIZE);
+ } else if (pal) {
+ av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
}
memcpy(frame->data[1], c->pal, AVPALETTE_SIZE);
}
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 5d5190002e..d5e1cc87f5 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -373,6 +373,10 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
w_align = 4;
h_align = 4;
}
+ if (s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
+ w_align = 8;
+ h_align = 8;
+ }
break;
case AV_PIX_FMT_PAL8:
case AV_PIX_FMT_BGR8:
@@ -382,7 +386,8 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
w_align = 4;
h_align = 4;
}
- if (s->codec_id == AV_CODEC_ID_JV) {
+ if (s->codec_id == AV_CODEC_ID_JV ||
+ s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
w_align = 8;
h_align = 8;
}
@@ -957,6 +962,7 @@ int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, v
if (ret)
ret[i] = r;
}
+ emms_c();
return 0;
}
@@ -969,6 +975,7 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2,
if (ret)
ret[i] = r;
}
+ emms_c();
return 0;
}
diff --git a/libavcodec/vdpau_hevc.c b/libavcodec/vdpau_hevc.c
index 3c1dc5f223..3223f5e2eb 100644
--- a/libavcodec/vdpau_hevc.c
+++ b/libavcodec/vdpau_hevc.c
@@ -245,7 +245,7 @@ static int vdpau_hevc_start_frame(AVCodecContext *avctx,
const HEVCFrame *frame = &h->DPB[i];
if (frame != h->ref && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF |
HEVC_FRAME_FLAG_SHORT_REF))) {
- if (j > 16) {
+ if (j > 15) {
av_log(avctx, AV_LOG_WARNING,
"VDPAU only supports up to 16 references in the DPB. "
"This frame may not be decoded correctly.\n");
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 5bbf47b52d..ea80c0e2b1 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -1071,6 +1071,9 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
s->dct_tokens[0][0] = s->dct_tokens_base;
+ if (get_bits_left(gb) < 16)
+ return AVERROR_INVALIDDATA;
+
/* fetch the DC table indexes */
dc_y_table = get_bits(gb, 4);
dc_c_table = get_bits(gb, 4);
@@ -1080,6 +1083,8 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
0, residual_eob_run);
if (residual_eob_run < 0)
return residual_eob_run;
+ if (get_bits_left(gb) < 8)
+ return AVERROR_INVALIDDATA;
/* reverse prediction of the Y-plane DC coefficients */
reverse_dc_prediction(s, 0, s->fragment_width[0], s->fragment_height[0]);
@@ -1102,6 +1107,8 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
s->fragment_width[1], s->fragment_height[1]);
}
+ if (get_bits_left(gb) < 8)
+ return AVERROR_INVALIDDATA;
/* fetch the AC table indexes */
ac_y_table = get_bits(gb, 4);
ac_c_table = get_bits(gb, 4);
@@ -2022,8 +2029,9 @@ static int vp3_decode_frame(AVCodecContext *avctx,
ret = vp3_decode_init(avctx);
if (ret < 0) {
vp3_decode_end(avctx);
+ return ret;
}
- return ret;
+ return buf_size;
} else if (type == 2) {
vp3_decode_end(avctx);
ret = theora_decode_tables(avctx, &gb);
@@ -2031,8 +2039,9 @@ static int vp3_decode_frame(AVCodecContext *avctx,
ret = vp3_decode_init(avctx);
if (ret < 0) {
vp3_decode_end(avctx);
+ return ret;
}
- return ret;
+ return buf_size;
}
av_log(avctx, AV_LOG_ERROR,
diff --git a/libavcodec/vp3dsp.c b/libavcodec/vp3dsp.c
index d8a3e0a354..37997431d3 100644
--- a/libavcodec/vp3dsp.c
+++ b/libavcodec/vp3dsp.c
@@ -41,7 +41,7 @@
#define xC6S2 25080
#define xC7S1 12785
-#define M(a, b) (((a) * (b)) >> 16)
+#define M(a, b) ((int)((SUINT)(a) * (b)) >> 16)
static av_always_inline void idct(uint8_t *dst, int stride,
int16_t *input, int type)
diff --git a/libavcodec/vp5.c b/libavcodec/vp5.c
index 5bcf9b6217..7100bb455d 100644
--- a/libavcodec/vp5.c
+++ b/libavcodec/vp5.c
@@ -39,8 +39,11 @@ static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
{
VP56RangeCoder *c = &s->c;
int rows, cols;
+ int ret;
- ff_vp56_init_range_decoder(&s->c, buf, buf_size);
+ ret = ff_vp56_init_range_decoder(&s->c, buf, buf_size);
+ if (ret < 0)
+ return ret;
s->frames[VP56_FRAME_CURRENT]->key_frame = !vp56_rac_get(c);
vp56_rac_get(c);
ff_vp56_init_dequant(s, vp56_rac_gets(c, 6));
@@ -171,7 +174,7 @@ static int vp5_parse_coeff_models(VP56Context *s)
return 0;
}
-static void vp5_parse_coeff(VP56Context *s)
+static int vp5_parse_coeff(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VP56Model *model = s->modelp;
@@ -181,6 +184,11 @@ static void vp5_parse_coeff(VP56Context *s)
int b, i, cg, idx, ctx, ctx_last;
int pt = 0; /* plane type (0 for Y, 1 for U or V) */
+ if (c->end <= c->buffer && c->bits >= 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "End of AC stream reached in vp5_parse_coeff\n");
+ return AVERROR_INVALIDDATA;
+ }
+
for (b=0; b<6; b++) {
int ct = 1; /* code type */
@@ -246,6 +254,7 @@ static void vp5_parse_coeff(VP56Context *s)
s->coeff_ctx[ff_vp56_b6to4[b]][i] = 5;
s->above_blocks[s->above_block_idx[b]].not_null_dc = s->coeff_ctx[ff_vp56_b6to4[b]][0];
}
+ return 0;
}
static void vp5_default_models_init(VP56Context *s)
diff --git a/libavcodec/vp56.c b/libavcodec/vp56.c
index 631924828d..bfc3d3bc7c 100644
--- a/libavcodec/vp56.c
+++ b/libavcodec/vp56.c
@@ -261,6 +261,25 @@ static VP56mb vp56_decode_mv(VP56Context *s, int row, int col)
return s->mb_type;
}
+static VP56mb vp56_conceal_mv(VP56Context *s, int row, int col)
+{
+ VP56mv *mv, vect = {0,0};
+ int b;
+
+ s->mb_type = VP56_MB_INTER_NOVEC_PF;
+ s->macroblocks[row * s->mb_width + col].type = s->mb_type;
+
+ mv = &vect;
+
+ s->macroblocks[row*s->mb_width + col].mv = *mv;
+
+ /* same vector for all blocks */
+ for (b=0; b<6; b++)
+ s->mv[b] = *mv;
+
+ return s->mb_type;
+}
+
static void vp56_add_predictors_dc(VP56Context *s, VP56Frame ref_frame)
{
int idx = s->idct_scantable[0];
@@ -381,20 +400,11 @@ static void vp56_mc(VP56Context *s, int b, int plane, uint8_t *src,
}
}
-static void vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
+static av_always_inline void vp56_render_mb(VP56Context *s, int row, int col, int is_alpha, VP56mb mb_type)
{
- AVFrame *frame_current, *frame_ref;
- VP56mb mb_type;
- VP56Frame ref_frame;
int b, ab, b_max, plane, off;
-
- if (s->frames[VP56_FRAME_CURRENT]->key_frame)
- mb_type = VP56_MB_INTRA;
- else
- mb_type = vp56_decode_mv(s, row, col);
- ref_frame = ff_vp56_reference_frame[mb_type];
-
- s->parse_coeff(s);
+ AVFrame *frame_current, *frame_ref;
+ VP56Frame ref_frame = ff_vp56_reference_frame[mb_type];
vp56_add_predictors_dc(s, ref_frame);
@@ -453,6 +463,39 @@ static void vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
}
}
+static int vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
+{
+ VP56mb mb_type;
+ int ret;
+
+ if (s->frames[VP56_FRAME_CURRENT]->key_frame)
+ mb_type = VP56_MB_INTRA;
+ else
+ mb_type = vp56_decode_mv(s, row, col);
+
+ ret = s->parse_coeff(s);
+ if (ret < 0)
+ return ret;
+
+ vp56_render_mb(s, row, col, is_alpha, mb_type);
+
+ return 0;
+}
+
+static int vp56_conceal_mb(VP56Context *s, int row, int col, int is_alpha)
+{
+ VP56mb mb_type;
+
+ if (s->frames[VP56_FRAME_CURRENT]->key_frame)
+ mb_type = VP56_MB_INTRA;
+ else
+ mb_type = vp56_conceal_mv(s, row, col);
+
+ vp56_render_mb(s, row, col, is_alpha, mb_type);
+
+ return 0;
+}
+
static int vp56_size_changed(VP56Context *s)
{
AVCodecContext *avctx = s->avctx;
@@ -464,6 +507,8 @@ static int vp56_size_changed(VP56Context *s)
s->plane_height[0] = s->plane_height[3] = avctx->coded_height;
s->plane_height[1] = s->plane_height[2] = avctx->coded_height/2;
+ s->have_undamaged_frame = 0;
+
for (i=0; i<4; i++)
s->stride[i] = s->flip * s->frames[VP56_FRAME_CURRENT]->linesize[i];
@@ -529,13 +574,18 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
}
ret = ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF);
- if (ret < 0)
+ if (ret < 0) {
+ if (res == VP56_SIZE_CHANGE)
+ ff_set_dimensions(avctx, 0, 0);
return ret;
+ }
if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) {
av_frame_unref(s->alpha_context->frames[VP56_FRAME_CURRENT]);
if ((ret = av_frame_ref(s->alpha_context->frames[VP56_FRAME_CURRENT], p)) < 0) {
av_frame_unref(p);
+ if (res == VP56_SIZE_CHANGE)
+ ff_set_dimensions(avctx, 0, 0);
return ret;
}
}
@@ -569,8 +619,12 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
}
}
+ s->discard_frame = 0;
avctx->execute2(avctx, ff_vp56_decode_mbs, 0, 0, (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) + 1);
+ if (s->discard_frame)
+ return AVERROR_INVALIDDATA;
+
if ((res = av_frame_ref(data, p)) < 0)
return res;
*got_frame = 1;
@@ -589,6 +643,7 @@ static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data,
int block, y, uv;
ptrdiff_t stride_y, stride_uv;
int res;
+ int damaged = 0;
if (p->key_frame) {
p->pict_type = AV_PICTURE_TYPE_I;
@@ -653,7 +708,18 @@ static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data,
s->block_offset[5] = s->block_offset[4];
for (mb_col=0; mb_col<s->mb_width; mb_col++) {
- vp56_decode_mb(s, mb_row, mb_col, is_alpha);
+ if (!damaged) {
+ int ret = vp56_decode_mb(s, mb_row, mb_col, is_alpha);
+ if (ret < 0) {
+ damaged = 1;
+ if (!s->have_undamaged_frame || !avctx->error_concealment) {
+ s->discard_frame = 1;
+ return AVERROR_INVALIDDATA;
+ }
+ }
+ }
+ if (damaged)
+ vp56_conceal_mb(s, mb_row, mb_col, is_alpha);
for (y=0; y<4; y++) {
s->above_block_idx[y] += 2;
@@ -667,6 +733,9 @@ static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data,
}
}
+ if (!damaged)
+ s->have_undamaged_frame = 1;
+
next:
if (p->key_frame || s->golden_frame) {
av_frame_unref(s->frames[VP56_FRAME_GOLDEN]);
diff --git a/libavcodec/vp56.h b/libavcodec/vp56.h
index 56c30919b7..c049399df8 100644
--- a/libavcodec/vp56.h
+++ b/libavcodec/vp56.h
@@ -74,7 +74,7 @@ typedef void (*VP56ParseVectorAdjustment)(VP56Context *s,
typedef void (*VP56Filter)(VP56Context *s, uint8_t *dst, uint8_t *src,
int offset1, int offset2, int stride,
VP56mv mv, int mask, int select, int luma);
-typedef void (*VP56ParseCoeff)(VP56Context *s);
+typedef int (*VP56ParseCoeff)(VP56Context *s);
typedef void (*VP56DefaultModelsInit)(VP56Context *s);
typedef void (*VP56ParseVectorModels)(VP56Context *s);
typedef int (*VP56ParseCoeffModels)(VP56Context *s);
@@ -203,6 +203,9 @@ struct vp56_context {
VLC runv_vlc[2];
VLC ract_vlc[2][3][6];
unsigned int nb_null[2][2]; /* number of consecutive NULL DC/AC */
+
+ int have_undamaged_frame;
+ int discard_frame;
};
@@ -221,7 +224,7 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
*/
extern const uint8_t ff_vp56_norm_shift[256];
-void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size);
+int ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size);
static av_always_inline unsigned int vp56_rac_renorm(VP56RangeCoder *c)
{
diff --git a/libavcodec/vp56rac.c b/libavcodec/vp56rac.c
index 6061b7ee72..e70302bf85 100644
--- a/libavcodec/vp56rac.c
+++ b/libavcodec/vp56rac.c
@@ -37,11 +37,14 @@ const uint8_t ff_vp56_norm_shift[256]= {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
-void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size)
+int ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size)
{
c->high = 255;
c->bits = -16;
c->buffer = buf;
c->end = buf + buf_size;
+ if (buf_size < 1)
+ return AVERROR_INVALIDDATA;
c->code_word = bytestream_get_be24(&c->buffer);
+ return 0;
}
diff --git a/libavcodec/vp6.c b/libavcodec/vp6.c
index a2bb4578d5..4afd67b3a4 100644
--- a/libavcodec/vp6.c
+++ b/libavcodec/vp6.c
@@ -40,8 +40,8 @@
#define VP6_MAX_HUFF_SIZE 12
-static void vp6_parse_coeff(VP56Context *s);
-static void vp6_parse_coeff_huffman(VP56Context *s);
+static int vp6_parse_coeff(VP56Context *s);
+static int vp6_parse_coeff_huffman(VP56Context *s);
static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
{
@@ -52,6 +52,7 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
int sub_version;
int rows, cols;
int res = 0;
+ int ret;
int separated_coeff = buf[0] & 1;
s->frames[VP56_FRAME_CURRENT]->key_frame = !(buf[0] & 0x80);
@@ -93,7 +94,7 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
s->avctx->coded_width = 16 * cols;
s->avctx->coded_height = 16 * rows;
} else {
- int ret = ff_set_dimensions(s->avctx, 16 * cols, 16 * rows);
+ ret = ff_set_dimensions(s->avctx, 16 * cols, 16 * rows);
if (ret < 0)
return ret;
@@ -105,7 +106,9 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
res = VP56_SIZE_CHANGE;
}
- ff_vp56_init_range_decoder(c, buf+6, buf_size-6);
+ ret = ff_vp56_init_range_decoder(c, buf+6, buf_size-6);
+ if (ret < 0)
+ goto fail;
vp56_rac_gets(c, 2);
parse_filter_info = s->filter_header;
@@ -122,7 +125,9 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
buf += 2;
buf_size -= 2;
}
- ff_vp56_init_range_decoder(c, buf+1, buf_size-1);
+ ret = ff_vp56_init_range_decoder(c, buf+1, buf_size-1);
+ if (ret < 0)
+ return ret;
s->golden_frame = vp56_rac_get(c);
if (s->filter_header) {
@@ -157,15 +162,16 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
buf += coeff_offset;
buf_size -= coeff_offset;
if (buf_size < 0) {
- if (s->frames[VP56_FRAME_CURRENT]->key_frame)
- ff_set_dimensions(s->avctx, 0, 0);
- return AVERROR_INVALIDDATA;
+ ret = AVERROR_INVALIDDATA;
+ goto fail;
}
if (s->use_huffman) {
s->parse_coeff = vp6_parse_coeff_huffman;
init_get_bits(&s->gb, buf, buf_size<<3);
} else {
- ff_vp56_init_range_decoder(&s->cc, buf, buf_size);
+ ret = ff_vp56_init_range_decoder(&s->cc, buf, buf_size);
+ if (ret < 0)
+ goto fail;
s->ccp = &s->cc;
}
} else {
@@ -173,6 +179,10 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
}
return res;
+fail:
+ if (res == VP56_SIZE_CHANGE)
+ ff_set_dimensions(s->avctx, 0, 0);
+ return ret;
}
static void vp6_coeff_order_table_init(VP56Context *s)
@@ -380,7 +390,7 @@ static unsigned vp6_get_nb_null(VP56Context *s)
return val;
}
-static void vp6_parse_coeff_huffman(VP56Context *s)
+static int vp6_parse_coeff_huffman(VP56Context *s)
{
VP56Model *model = s->modelp;
uint8_t *permute = s->idct_scantable;
@@ -402,7 +412,7 @@ static void vp6_parse_coeff_huffman(VP56Context *s)
break;
} else {
if (get_bits_left(&s->gb) <= 0)
- return;
+ return AVERROR_INVALIDDATA;
coeff = get_vlc2(&s->gb, vlc_coeff->table, FF_HUFFMAN_BITS, 3);
if (coeff == 0) {
if (coeff_idx) {
@@ -437,9 +447,10 @@ static void vp6_parse_coeff_huffman(VP56Context *s)
vlc_coeff = &s->ract_vlc[pt][ct][cg];
}
}
+ return 0;
}
-static void vp6_parse_coeff(VP56Context *s)
+static int vp6_parse_coeff(VP56Context *s)
{
VP56RangeCoder *c = s->ccp;
VP56Model *model = s->modelp;
@@ -449,6 +460,11 @@ static void vp6_parse_coeff(VP56Context *s)
int b, i, cg, idx, ctx;
int pt = 0; /* plane type (0 for Y, 1 for U or V) */
+ if (c->end <= c->buffer && c->bits >= 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "End of AC stream reached in vp6_parse_coeff\n");
+ return AVERROR_INVALIDDATA;
+ }
+
for (b=0; b<6; b++) {
int ct = 1; /* code type */
int run = 1;
@@ -512,6 +528,7 @@ static void vp6_parse_coeff(VP56Context *s)
s->left_block[ff_vp56_b6to4[b]].not_null_dc =
s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0];
}
+ return 0;
}
static int vp6_block_variance(uint8_t *src, int stride)
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 64037fc089..7511f4dfc9 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -260,6 +260,7 @@ static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size)
{
const uint8_t *sizes = buf;
int i;
+ int ret;
s->num_coeff_partitions = 1 << vp8_rac_get_uint(&s->c, 2);
@@ -273,13 +274,13 @@ static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size)
if (buf_size - size < 0)
return -1;
- ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, size);
+ ret = ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, size);
+ if (ret < 0)
+ return ret;
buf += size;
buf_size -= size;
}
- ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, buf_size);
-
- return 0;
+ return ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, buf_size);
}
static void vp7_get_quants(VP8Context *s)
@@ -517,7 +518,9 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab, sizeof(s->put_pixels_tab));
- ff_vp56_init_range_decoder(c, buf, part1_size);
+ ret = ff_vp56_init_range_decoder(c, buf, part1_size);
+ if (ret < 0)
+ return ret;
buf += part1_size;
buf_size -= part1_size;
@@ -569,7 +572,9 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
s->lf_delta.enabled = 0;
s->num_coeff_partitions = 1;
- ff_vp56_init_range_decoder(&s->coeff_partition[0], buf, buf_size);
+ ret = ff_vp56_init_range_decoder(&s->coeff_partition[0], buf, buf_size);
+ if (ret < 0)
+ return ret;
if (!s->macroblocks_base || /* first frame */
width != s->avctx->width || height != s->avctx->height ||
@@ -698,7 +703,9 @@ static int vp8_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
memset(&s->lf_delta, 0, sizeof(s->lf_delta));
}
- ff_vp56_init_range_decoder(c, buf, header_size);
+ ret = ff_vp56_init_range_decoder(c, buf, header_size);
+ if (ret < 0)
+ return ret;
buf += header_size;
buf_size -= header_size;
@@ -2274,7 +2281,7 @@ static void vp8_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *cur_frame,
#define update_pos(td, mb_y, mb_x) while(0)
#endif
-static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
+static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
int jobnr, int threadnr, int is_vp7)
{
VP8Context *s = avctx->priv_data;
@@ -2290,6 +2297,10 @@ static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void
curframe->tf.f->data[1] + 8 * mb_y * s->uvlinesize,
curframe->tf.f->data[2] + 8 * mb_y * s->uvlinesize
};
+
+ if (c->end <= c->buffer && c->bits >= 0)
+ return AVERROR_INVALIDDATA;
+
if (mb_y == 0)
prev_td = td;
else
@@ -2318,6 +2329,8 @@ static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void
s->mv_max.x = ((s->mb_width - 1) << 6) + MARGIN;
for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
+ if (c->end <= c->buffer && c->bits >= 0)
+ return AVERROR_INVALIDDATA;
// Wait for previous thread to read mb_x+2, and reach mb_y-1.
if (prev_td != td) {
if (threadnr != 0) {
@@ -2393,18 +2406,19 @@ static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void
update_pos(td, mb_y, mb_x);
}
}
+ return 0;
}
-static void vp7_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
+static int vp7_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
int jobnr, int threadnr)
{
- decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 1);
+ return decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 1);
}
-static void vp8_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
+static int vp8_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
int jobnr, int threadnr)
{
- decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 0);
+ return decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 0);
}
static av_always_inline void filter_mb_row(AVCodecContext *avctx, void *tdata,
@@ -2487,13 +2501,16 @@ int vp78_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata, int jobnr,
VP8ThreadData *next_td = NULL, *prev_td = NULL;
VP8Frame *curframe = s->curframe;
int mb_y, num_jobs = s->num_jobs;
+ int ret;
td->thread_nr = threadnr;
for (mb_y = jobnr; mb_y < s->mb_height; mb_y += num_jobs) {
- if (mb_y >= s->mb_height)
- break;
td->thread_mb_pos = mb_y << 16;
- s->decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr);
+ ret = s->decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr);
+ if (ret < 0) {
+ update_pos(td, s->mb_height, INT_MAX & 0xFFFF);
+ return ret;
+ }
if (s->deblock_filter)
s->filter_mb_row(avctx, tdata, jobnr, threadnr);
update_pos(td, mb_y, INT_MAX & 0xFFFF);
@@ -2530,6 +2547,8 @@ int vp78_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
enum AVDiscard skip_thresh;
VP8Frame *av_uninit(curframe), *prev_frame;
+ av_assert0(avctx->pix_fmt == AV_PIX_FMT_YUVA420P || avctx->pix_fmt == AV_PIX_FMT_YUV420P);
+
if (is_vp7)
ret = vp7_decode_frame_header(s, avpkt->data, avpkt->size);
else
diff --git a/libavcodec/vp8.h b/libavcodec/vp8.h
index cfd82aaaba..81ffe2c144 100644
--- a/libavcodec/vp8.h
+++ b/libavcodec/vp8.h
@@ -275,7 +275,7 @@ typedef struct VP8Context {
*/
int mb_layout;
- void (*decode_mb_row_no_filter)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);
+ int (*decode_mb_row_no_filter)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);
void (*filter_mb_row)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);
int vp7;
diff --git a/libavcodec/vp8dsp.c b/libavcodec/vp8dsp.c
index 07bea69c78..fed5c67a90 100644
--- a/libavcodec/vp8dsp.c
+++ b/libavcodec/vp8dsp.c
@@ -53,7 +53,8 @@ static void name ## _idct_dc_add4y_c(uint8_t *dst, int16_t block[4][16], \
#if CONFIG_VP7_DECODER
static void vp7_luma_dc_wht_c(int16_t block[4][4][16], int16_t dc[16])
{
- int i, a1, b1, c1, d1;
+ int i;
+ unsigned a1, b1, c1, d1;
int16_t tmp[16];
for (i = 0; i < 4; i++) {
@@ -61,10 +62,10 @@ static void vp7_luma_dc_wht_c(int16_t block[4][4][16], int16_t dc[16])
b1 = (dc[i * 4 + 0] - dc[i * 4 + 2]) * 23170;
c1 = dc[i * 4 + 1] * 12540 - dc[i * 4 + 3] * 30274;
d1 = dc[i * 4 + 1] * 30274 + dc[i * 4 + 3] * 12540;
- tmp[i * 4 + 0] = (a1 + d1) >> 14;
- tmp[i * 4 + 3] = (a1 - d1) >> 14;
- tmp[i * 4 + 1] = (b1 + c1) >> 14;
- tmp[i * 4 + 2] = (b1 - c1) >> 14;
+ tmp[i * 4 + 0] = (int)(a1 + d1) >> 14;
+ tmp[i * 4 + 3] = (int)(a1 - d1) >> 14;
+ tmp[i * 4 + 1] = (int)(b1 + c1) >> 14;
+ tmp[i * 4 + 2] = (int)(b1 - c1) >> 14;
}
for (i = 0; i < 4; i++) {
@@ -73,10 +74,10 @@ static void vp7_luma_dc_wht_c(int16_t block[4][4][16], int16_t dc[16])
c1 = tmp[i + 4] * 12540 - tmp[i + 12] * 30274;
d1 = tmp[i + 4] * 30274 + tmp[i + 12] * 12540;
AV_ZERO64(dc + i * 4);
- block[0][i][0] = (a1 + d1 + 0x20000) >> 18;
- block[3][i][0] = (a1 - d1 + 0x20000) >> 18;
- block[1][i][0] = (b1 + c1 + 0x20000) >> 18;
- block[2][i][0] = (b1 - c1 + 0x20000) >> 18;
+ block[0][i][0] = (int)(a1 + d1 + 0x20000) >> 18;
+ block[3][i][0] = (int)(a1 - d1 + 0x20000) >> 18;
+ block[1][i][0] = (int)(b1 + c1 + 0x20000) >> 18;
+ block[2][i][0] = (int)(b1 - c1 + 0x20000) >> 18;
}
}
@@ -95,7 +96,8 @@ static void vp7_luma_dc_wht_dc_c(int16_t block[4][4][16], int16_t dc[16])
static void vp7_idct_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)
{
- int i, a1, b1, c1, d1;
+ int i;
+ unsigned a1, b1, c1, d1;
int16_t tmp[16];
for (i = 0; i < 4; i++) {
@@ -104,10 +106,10 @@ static void vp7_idct_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)
c1 = block[i * 4 + 1] * 12540 - block[i * 4 + 3] * 30274;
d1 = block[i * 4 + 1] * 30274 + block[i * 4 + 3] * 12540;
AV_ZERO64(block + i * 4);
- tmp[i * 4 + 0] = (a1 + d1) >> 14;
- tmp[i * 4 + 3] = (a1 - d1) >> 14;
- tmp[i * 4 + 1] = (b1 + c1) >> 14;
- tmp[i * 4 + 2] = (b1 - c1) >> 14;
+ tmp[i * 4 + 0] = (int)(a1 + d1) >> 14;
+ tmp[i * 4 + 3] = (int)(a1 - d1) >> 14;
+ tmp[i * 4 + 1] = (int)(b1 + c1) >> 14;
+ tmp[i * 4 + 2] = (int)(b1 - c1) >> 14;
}
for (i = 0; i < 4; i++) {
@@ -116,13 +118,13 @@ static void vp7_idct_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)
c1 = tmp[i + 4] * 12540 - tmp[i + 12] * 30274;
d1 = tmp[i + 4] * 30274 + tmp[i + 12] * 12540;
dst[0 * stride + i] = av_clip_uint8(dst[0 * stride + i] +
- ((a1 + d1 + 0x20000) >> 18));
+ ((int)(a1 + d1 + 0x20000) >> 18));
dst[3 * stride + i] = av_clip_uint8(dst[3 * stride + i] +
- ((a1 - d1 + 0x20000) >> 18));
+ ((int)(a1 - d1 + 0x20000) >> 18));
dst[1 * stride + i] = av_clip_uint8(dst[1 * stride + i] +
- ((b1 + c1 + 0x20000) >> 18));
+ ((int)(b1 + c1 + 0x20000) >> 18));
dst[2 * stride + i] = av_clip_uint8(dst[2 * stride + i] +
- ((b1 - c1 + 0x20000) >> 18));
+ ((int)(b1 - c1 + 0x20000) >> 18));
}
}
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 5c6f176367..7010e8ce10 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -842,7 +842,10 @@ static int decode_frame_header(AVCodecContext *ctx,
av_log(ctx, AV_LOG_ERROR, "Invalid compressed header size\n");
return AVERROR_INVALIDDATA;
}
- ff_vp56_init_range_decoder(&s->c, data2, size2);
+ res = ff_vp56_init_range_decoder(&s->c, data2, size2);
+ if (res < 0)
+ return res;
+
if (vp56_rac_get_prob_branchy(&s->c, 128)) { // marker bit
av_log(ctx, AV_LOG_ERROR, "Marker bit was set\n");
return AVERROR_INVALIDDATA;
@@ -3703,11 +3706,10 @@ static av_always_inline void adapt_prob(uint8_t *p, unsigned ct0, unsigned ct1,
if (!ct)
return;
+ update_factor = FASTDIV(update_factor * FFMIN(ct, max_count), max_count);
p1 = *p;
- p2 = ((ct0 << 8) + (ct >> 1)) / ct;
+ p2 = ((((int64_t) ct0) << 8) + (ct >> 1)) / ct;
p2 = av_clip(p2, 1, 255);
- ct = FFMIN(ct, max_count);
- update_factor = FASTDIV(update_factor * ct, max_count);
// (p1 * (256 - update_factor) + p2 * update_factor + 128) >> 8
*p = p1 + (((p2 - p1) * update_factor + 128) >> 8);
@@ -4127,7 +4129,9 @@ static int vp9_decode_frame(AVCodecContext *ctx, void *frame,
ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, INT_MAX, 0);
return AVERROR_INVALIDDATA;
}
- ff_vp56_init_range_decoder(&s->c_b[tile_col], data, tile_size);
+ res = ff_vp56_init_range_decoder(&s->c_b[tile_col], data, tile_size);
+ if (res < 0)
+ return res;
if (vp56_rac_get_prob_branchy(&s->c_b[tile_col], 128)) { // marker bit
ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, INT_MAX, 0);
return AVERROR_INVALIDDATA;
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index b6022f0fa5..f828fc725b 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -267,7 +267,7 @@ static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc,
int bit;
if (s->extra_bits) {
- S <<= s->extra_bits;
+ S *= 1 << s->extra_bits;
if (s->got_extra_bits &&
get_bits_left(&s->gb_extra_bits) >= s->extra_bits) {
@@ -682,7 +682,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
s->post_shift = bpp * 8 - orig_bpp + ((s->frame_flags >> 13) & 0x1f);
s->hybrid_maxclip = ((1LL << (orig_bpp - 1)) - 1);
- s->hybrid_minclip = ((-1LL << (orig_bpp - 1)));
+ s->hybrid_minclip = ((-1UL << (orig_bpp - 1)));
s->CRC = bytestream2_get_le32(&gb);
// parse metadata blocks
@@ -736,13 +736,13 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
}
for (i = 0; i < weights; i++) {
t = (int8_t)bytestream2_get_byte(&gb);
- s->decorr[s->terms - i - 1].weightA = t << 3;
+ s->decorr[s->terms - i - 1].weightA = t * (1 << 3);
if (s->decorr[s->terms - i - 1].weightA > 0)
s->decorr[s->terms - i - 1].weightA +=
(s->decorr[s->terms - i - 1].weightA + 64) >> 7;
if (s->stereo_in) {
t = (int8_t)bytestream2_get_byte(&gb);
- s->decorr[s->terms - i - 1].weightB = t << 3;
+ s->decorr[s->terms - i - 1].weightB = t * (1 << 3);
if (s->decorr[s->terms - i - 1].weightB > 0)
s->decorr[s->terms - i - 1].weightB +=
(s->decorr[s->terms - i - 1].weightB + 64) >> 7;
@@ -837,7 +837,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
continue;
}
bytestream2_get_buffer(&gb, val, 4);
- if (val[0] > 32) {
+ if (val[0] > 31) {
av_log(avctx, AV_LOG_ERROR,
"Invalid INT32INFO, extra_bits = %d (> 32)\n", val[0]);
continue;
diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index 5c2961ff19..e119a25799 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -694,7 +694,7 @@ static int decode_entropy_coded_image(WebPContext *s, enum ImageRole role,
length = offset + get_bits(&s->gb, extra_bits) + 1;
}
prefix_code = huff_reader_get_symbol(&hg[HUFF_IDX_DIST], &s->gb);
- if (prefix_code > 39) {
+ if (prefix_code > 39U) {
av_log(s->avctx, AV_LOG_ERROR,
"distance prefix code too large: %d\n", prefix_code);
return AVERROR_INVALIDDATA;
@@ -1043,7 +1043,7 @@ static int apply_color_indexing_transform(WebPContext *s)
uint8_t *line;
int pixel_bits = 8 >> pal->size_reduction;
- line = av_malloc(img->frame->linesize[0]);
+ line = av_malloc(img->frame->linesize[0] + AV_INPUT_BUFFER_PADDING_SIZE);
if (!line)
return AVERROR(ENOMEM);
@@ -1099,6 +1099,21 @@ static int apply_color_indexing_transform(WebPContext *s)
return 0;
}
+static void update_canvas_size(AVCodecContext *avctx, int w, int h)
+{
+ WebPContext *s = avctx->priv_data;
+ if (s->width && s->width != w) {
+ av_log(avctx, AV_LOG_WARNING, "Width mismatch. %d != %d\n",
+ s->width, w);
+ }
+ s->width = w;
+ if (s->height && s->height != h) {
+ av_log(avctx, AV_LOG_WARNING, "Height mismatch. %d != %d\n",
+ s->height, h);
+ }
+ s->height = h;
+}
+
static int vp8_lossless_decode_frame(AVCodecContext *avctx, AVFrame *p,
int *got_frame, uint8_t *data_start,
unsigned int data_size, int is_alpha_chunk)
@@ -1123,16 +1138,8 @@ static int vp8_lossless_decode_frame(AVCodecContext *avctx, AVFrame *p,
w = get_bits(&s->gb, 14) + 1;
h = get_bits(&s->gb, 14) + 1;
- if (s->width && s->width != w) {
- av_log(avctx, AV_LOG_WARNING, "Width mismatch. %d != %d\n",
- s->width, w);
- }
- s->width = w;
- if (s->height && s->height != h) {
- av_log(avctx, AV_LOG_WARNING, "Height mismatch. %d != %d\n",
- s->width, w);
- }
- s->height = h;
+
+ update_canvas_size(avctx, w, h);
ret = ff_set_dimensions(avctx, s->width, s->height);
if (ret < 0)
@@ -1327,9 +1334,8 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p,
if (!s->initialized) {
ff_vp8_decode_init(avctx);
s->initialized = 1;
- if (s->has_alpha)
- avctx->pix_fmt = AV_PIX_FMT_YUVA420P;
}
+ avctx->pix_fmt = s->has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P;
s->lossless = 0;
if (data_size > INT_MAX) {
@@ -1342,6 +1348,11 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p,
pkt.size = data_size;
ret = ff_vp8_decode_frame(avctx, p, got_frame, &pkt);
+ if (ret < 0)
+ return ret;
+
+ update_canvas_size(avctx, avctx->width, avctx->height);
+
if (s->has_alpha) {
ret = vp8_lossy_decode_alpha(avctx, p, s->alpha_data,
s->alpha_data_size);
diff --git a/libavcodec/wmv2dsp.c b/libavcodec/wmv2dsp.c
index 40e0bef0da..7b59d10a43 100644
--- a/libavcodec/wmv2dsp.c
+++ b/libavcodec/wmv2dsp.c
@@ -48,8 +48,8 @@ static void wmv2_idct_row(short * b)
a4 = W0 * b[0] - W0 * b[4];
/* step 2 */
- s1 = (181 * (a1 - a5 + a7 - a3) + 128) >> 8; // 1, 3, 5, 7
- s2 = (181 * (a1 - a5 - a7 + a3) + 128) >> 8;
+ s1 = (int)(181U * (a1 - a5 + a7 - a3) + 128) >> 8; // 1, 3, 5, 7
+ s2 = (int)(181U * (a1 - a5 - a7 + a3) + 128) >> 8;
/* step 3 */
b[0] = (a0 + a2 + a1 + a5 + (1 << 7)) >> 8;
@@ -78,8 +78,8 @@ static void wmv2_idct_col(short * b)
a4 = (W0 * b[8 * 0] - W0 * b[8 * 4] ) >> 3;
/* step 2 */
- s1 = (181 * (a1 - a5 + a7 - a3) + 128) >> 8;
- s2 = (181 * (a1 - a5 - a7 + a3) + 128) >> 8;
+ s1 = (int)(181U * (a1 - a5 + a7 - a3) + 128) >> 8;
+ s2 = (int)(181U * (a1 - a5 - a7 + a3) + 128) >> 8;
/* step 3 */
b[8 * 0] = (a0 + a2 + a1 + a5 + (1 << 13)) >> 14;
diff --git a/libavcodec/wnv1.c b/libavcodec/wnv1.c
index 9ff99b2f98..126c01a02d 100644
--- a/libavcodec/wnv1.c
+++ b/libavcodec/wnv1.c
@@ -52,7 +52,7 @@ static inline int wnv1_get_code(WNV1Context *w, int base_value)
if (v == 15)
return ff_reverse[get_bits(&w->gb, 8 - w->shift)];
else
- return base_value + ((v - 7) << w->shift);
+ return base_value + ((v - 7U) << w->shift);
}
static int decode_frame(AVCodecContext *avctx,
diff --git a/libavcodec/x86/vc1dsp_init.c b/libavcodec/x86/vc1dsp_init.c
index c8943fa2f7..c53a1328f2 100644
--- a/libavcodec/x86/vc1dsp_init.c
+++ b/libavcodec/x86/vc1dsp_init.c
@@ -106,10 +106,12 @@ av_cold void ff_vc1dsp_init_x86(VC1DSPContext *dsp)
{
int cpu_flags = av_get_cpu_flags();
- if (HAVE_6REGS && INLINE_MMX(cpu_flags) && EXTERNAL_MMX(cpu_flags))
+ if (HAVE_6REGS && INLINE_MMX(cpu_flags))
+ if (EXTERNAL_MMX(cpu_flags))
ff_vc1dsp_init_mmx(dsp);
- if (HAVE_6REGS && INLINE_MMXEXT(cpu_flags) && EXTERNAL_MMXEXT(cpu_flags))
+ if (HAVE_6REGS && INLINE_MMXEXT(cpu_flags))
+ if (EXTERNAL_MMXEXT(cpu_flags))
ff_vc1dsp_init_mmxext(dsp);
#define ASSIGN_LF(EXT) \
diff --git a/libavcodec/xwddec.c b/libavcodec/xwddec.c
index 64cd8418a2..8b0845fc01 100644
--- a/libavcodec/xwddec.c
+++ b/libavcodec/xwddec.c
@@ -157,9 +157,9 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data,
case XWD_GRAY_SCALE:
if (bpp != 1 && bpp != 8)
return AVERROR_INVALIDDATA;
- if (pixdepth == 1) {
+ if (bpp == 1 && pixdepth == 1) {
avctx->pix_fmt = AV_PIX_FMT_MONOWHITE;
- } else if (pixdepth == 8) {
+ } else if (bpp == 8 && pixdepth == 8) {
avctx->pix_fmt = AV_PIX_FMT_GRAY8;
}
break;
diff --git a/libavcodec/y41pdec.c b/libavcodec/y41pdec.c
index 1b177d4262..85a39e4ae2 100644
--- a/libavcodec/y41pdec.c
+++ b/libavcodec/y41pdec.c
@@ -43,7 +43,7 @@ static int y41p_decode_frame(AVCodecContext *avctx, void *data,
uint8_t *y, *u, *v;
int i, j, ret;
- if (avpkt->size < 3LL * avctx->height * avctx->width / 2) {
+ if (avpkt->size < 3LL * avctx->height * FFALIGN(avctx->width, 8) / 2) {
av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
return AVERROR(EINVAL);
}
diff --git a/libavfilter/af_pan.c b/libavfilter/af_pan.c
index 1eb102c10a..7c02f6720d 100644
--- a/libavfilter/af_pan.c
+++ b/libavfilter/af_pan.c
@@ -109,7 +109,7 @@ static av_cold int init(AVFilterContext *ctx)
if (!pan->args) {
av_log(ctx, AV_LOG_ERROR,
"pan filter needs a channel layout and a set "
- "of channels definitions as parameter\n");
+ "of channel definitions as parameter\n");
return AVERROR(EINVAL);
}
if (!args)
@@ -276,7 +276,7 @@ static int config_props(AVFilterLink *link)
if (link->channels > MAX_CHANNELS ||
pan->nb_output_channels > MAX_CHANNELS) {
av_log(ctx, AV_LOG_ERROR,
- "af_pan support a maximum of %d channels. "
+ "af_pan supports a maximum of %d channels. "
"Feel free to ask for a higher limit.\n", MAX_CHANNELS);
return AVERROR_PATCHWELCOME;
}
diff --git a/libavfilter/af_sofalizer.c b/libavfilter/af_sofalizer.c
index 0f1231f884..eda98b08bb 100644
--- a/libavfilter/af_sofalizer.c
+++ b/libavfilter/af_sofalizer.c
@@ -375,7 +375,7 @@ static int get_speaker_pos(AVFilterContext *ctx,
/* set speaker positions according to input channel configuration: */
for (m = 0, ch = 0; ch < n_conv && m < 64; m++) {
- uint64_t mask = channels_layout & (1 << m);
+ uint64_t mask = channels_layout & (1ULL << m);
switch (mask) {
case AV_CH_FRONT_LEFT: azim[ch] = 30; break;
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 9f50b4120d..b6f795bff8 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -858,6 +858,8 @@ static void swap_samplerates_on_filter(AVFilterContext *filter)
for (j = 0; j < outlink->in_samplerates->nb_formats; j++) {
int diff = abs(sample_rate - outlink->in_samplerates->formats[j]);
+ av_assert0(diff < INT_MAX); // This would lead to the use of uninitialized best_diff but is only possible with invalid sample rates
+
if (diff < best_diff) {
best_diff = diff;
best_idx = j;
diff --git a/libavfilter/vf_blackframe.c b/libavfilter/vf_blackframe.c
index ad6d488b3a..9fe2a42942 100644
--- a/libavfilter/vf_blackframe.c
+++ b/libavfilter/vf_blackframe.c
@@ -104,8 +104,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
#define OFFSET(x) offsetof(BlackFrameContext, x)
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
static const AVOption blackframe_options[] = {
- { "amount", "Percentage of the pixels that have to be below the threshold "
- "for the frame to be considered black.", OFFSET(bamount), AV_OPT_TYPE_INT, { .i64 = 98 }, 0, 100, FLAGS },
+ { "amount", "percentage of the pixels that have to be below the threshold "
+ "for the frame to be considered black", OFFSET(bamount), AV_OPT_TYPE_INT, { .i64 = 98 }, 0, 100, FLAGS },
{ "threshold", "threshold below which a pixel value is considered black",
OFFSET(bthresh), AV_OPT_TYPE_INT, { .i64 = 32 }, 0, 255, FLAGS },
{ "thresh", "threshold below which a pixel value is considered black",
diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
index f963254e11..41f72161d9 100644
--- a/libavfilter/vf_uspp.c
+++ b/libavfilter/vf_uspp.c
@@ -227,8 +227,8 @@ static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3],
p->frame->quality = ff_norm_qscale((qpsum + qpcount/2) / qpcount, p->qscale_type) * FF_QP2LAMBDA;
}
// init per MB qscale stuff FIXME
- p->frame->height = height;
- p->frame->width = width;
+ p->frame->height = height + BLOCK;
+ p->frame->width = width + BLOCK;
for (i = 0; i < count; i++) {
const int x1 = offset[i+count-1][0];
diff --git a/libavformat/apngdec.c b/libavformat/apngdec.c
index c6403a191d..d9f9ee3f30 100644
--- a/libavformat/apngdec.c
+++ b/libavformat/apngdec.c
@@ -269,7 +269,7 @@ static int decode_fctl_chunk(AVFormatContext *s, APNGDemuxContext *ctx, AVPacket
/* default is hundredths of seconds */
if (!delay_den)
delay_den = 100;
- if (!delay_num || delay_den / delay_num > ctx->max_fps) {
+ if (!delay_num || (ctx->max_fps && delay_den / delay_num > ctx->max_fps)) {
delay_num = 1;
delay_den = ctx->default_fps;
}
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 34bad436cd..06a71c97ff 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1866,6 +1866,13 @@ typedef struct AVFormatContext {
* A callback for closing the streams opened with AVFormatContext.io_open().
*/
void (*io_close)(struct AVFormatContext *s, AVIOContext *pb);
+
+ /**
+ * The maximum number of streams.
+ * - encoding: unused
+ * - decoding: set by user through AVOptions (NO direct access)
+ */
+ int max_streams;
} AVFormatContext;
int av_format_get_probe_score(const AVFormatContext *s);
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 7adb819346..955b27b857 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -1191,7 +1191,8 @@ start_sync:
if ((d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) ||
// parse JUNK
(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') ||
- (d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1')) {
+ (d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1') ||
+ (d[0] == 'i' && d[1] == 'n' && d[2] == 'd' && d[3] == 'x')) {
avio_skip(pb, size);
goto start_sync;
}
diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index de7b89a28f..9c7484eb95 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -193,8 +193,11 @@ static int detect_stream_specific(AVFormatContext *avf, int idx)
ConcatStream *cs = &cat->cur_file->streams[idx];
AVBitStreamFilterContext *bsf;
- if (cat->auto_convert && st->codec->codec_id == AV_CODEC_ID_H264 &&
- (st->codec->extradata_size < 4 || AV_RB32(st->codec->extradata) != 1)) {
+ if (cat->auto_convert && st->codec->codec_id == AV_CODEC_ID_H264) {
+ if (!st->codec->extradata_size ||
+ (st->codec->extradata_size >= 3 && AV_RB24(st->codec->extradata) == 1) ||
+ (st->codec->extradata_size >= 4 && AV_RB32(st->codec->extradata) == 1))
+ return 0;
av_log(cat->avf, AV_LOG_INFO,
"Auto-inserting h264_mp4toannexb bitstream filter\n");
if (!(bsf = av_bitstream_filter_init("h264_mp4toannexb"))) {
diff --git a/libavformat/dcstr.c b/libavformat/dcstr.c
index 2ae61dec85..e9714e504f 100644
--- a/libavformat/dcstr.c
+++ b/libavformat/dcstr.c
@@ -33,6 +33,7 @@ static int dcstr_probe(AVProbeData *p)
static int dcstr_read_header(AVFormatContext *s)
{
unsigned codec, align;
+ int mult;
AVStream *st;
st = avformat_new_stream(s, NULL);
@@ -46,7 +47,12 @@ static int dcstr_read_header(AVFormatContext *s)
align = avio_rl32(s->pb);
avio_skip(s->pb, 4);
st->duration = avio_rl32(s->pb);
- st->codec->channels *= avio_rl32(s->pb);
+ mult = avio_rl32(s->pb);
+ if (st->codec->channels <= 0 || mult <= 0 || mult > INT_MAX / st->codec->channels) {
+ av_log(s, AV_LOG_ERROR, "invalid number of channels %d x %d\n", st->codec->channels, mult);
+ return AVERROR_INVALIDDATA;
+ }
+ st->codec->channels *= mult;
if (!align || align > INT_MAX / st->codec->channels)
return AVERROR_INVALIDDATA;
st->codec->block_align = align * st->codec->channels;
diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c
index 83929fe8c3..44110af701 100644
--- a/libavformat/ffmdec.c
+++ b/libavformat/ffmdec.c
@@ -362,7 +362,7 @@ static int ffm2_read_header(AVFormatContext *s)
}
break;
case MKBETAG('S', 'T', 'V', 'I'):
- if (f_stvi++) {
+ if (f_stvi++ || codec->codec_type != AVMEDIA_TYPE_VIDEO) {
ret = AVERROR(EINVAL);
goto fail;
}
@@ -423,7 +423,7 @@ static int ffm2_read_header(AVFormatContext *s)
codec->refs = avio_rb32(pb);
break;
case MKBETAG('S', 'T', 'A', 'U'):
- if (f_stau++) {
+ if (f_stau++ || codec->codec_type != AVMEDIA_TYPE_AUDIO) {
ret = AVERROR(EINVAL);
goto fail;
}
@@ -449,7 +449,7 @@ static int ffm2_read_header(AVFormatContext *s)
}
break;
case MKBETAG('S', '2', 'V', 'I'):
- if (f_stvi++ || !size) {
+ if (f_stvi++ || !size || codec->codec_type != AVMEDIA_TYPE_VIDEO) {
ret = AVERROR(EINVAL);
goto fail;
}
@@ -464,7 +464,7 @@ static int ffm2_read_header(AVFormatContext *s)
goto fail;
break;
case MKBETAG('S', '2', 'A', 'U'):
- if (f_stau++ || !size) {
+ if (f_stau++ || !size || codec->codec_type != AVMEDIA_TYPE_AUDIO) {
ret = AVERROR(EINVAL);
goto fail;
}
diff --git a/libavformat/filmstripdec.c b/libavformat/filmstripdec.c
index cdbb93b11a..b28854fa5e 100644
--- a/libavformat/filmstripdec.c
+++ b/libavformat/filmstripdec.c
@@ -25,6 +25,7 @@
*/
#include "libavutil/intreadwrite.h"
+#include "libavutil/imgutils.h"
#include "avformat.h"
#include "internal.h"
@@ -68,10 +69,8 @@ static int read_header(AVFormatContext *s)
st->codec->height = avio_rb16(pb);
film->leading = avio_rb16(pb);
- if (st->codec->width * 4LL * st->codec->height >= INT_MAX) {
- av_log(s, AV_LOG_ERROR, "dimensions too large\n");
- return AVERROR_PATCHWELCOME;
- }
+ if (av_image_check_size(st->codec->width, st->codec->height, 0, s) < 0)
+ return AVERROR_INVALIDDATA;
avpriv_set_pts_info(st, 64, 1, avio_rb16(pb));
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 46c51a6453..9553106f34 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -65,7 +65,8 @@ static int flac_read_header(AVFormatContext *s)
/* process metadata blocks */
while (!avio_feof(s->pb) && !metadata_last) {
- avio_read(s->pb, header, 4);
+ if (avio_read(s->pb, header, 4) != 4)
+ return AVERROR(AVERROR_INVALIDDATA);
flac_parse_block_header(header, &metadata_last, &metadata_type,
&metadata_size);
switch (metadata_type) {
diff --git a/libavformat/http.c b/libavformat/http.c
index 3dad2ef9fb..5bb8d586de 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -62,8 +62,8 @@ typedef struct HTTPContext {
int line_count;
int http_code;
/* Used if "Transfer-Encoding: chunked" otherwise -1. */
- int64_t chunksize;
- int64_t off, end_off, filesize;
+ uint64_t chunksize;
+ uint64_t off, end_off, filesize;
char *location;
HTTPAuthState auth_state;
HTTPAuthState proxy_auth_state;
@@ -92,9 +92,9 @@ typedef struct HTTPContext {
AVDictionary *cookie_dict;
int icy;
/* how much data was read since the last ICY metadata packet */
- int icy_data_read;
+ uint64_t icy_data_read;
/* after how many bytes of read data a new metadata packet will be found */
- int icy_metaint;
+ uint64_t icy_metaint;
char *icy_metadata_headers;
char *icy_metadata_packet;
AVDictionary *metadata;
@@ -480,7 +480,7 @@ static int http_open(URLContext *h, const char *uri, int flags,
else
h->is_streamed = 1;
- s->filesize = -1;
+ s->filesize = UINT64_MAX;
s->location = av_strdup(uri);
if (!s->location)
return AVERROR(ENOMEM);
@@ -607,9 +607,9 @@ static void parse_content_range(URLContext *h, const char *p)
if (!strncmp(p, "bytes ", 6)) {
p += 6;
- s->off = strtoll(p, NULL, 10);
+ s->off = strtoull(p, NULL, 10);
if ((slash = strchr(p, '/')) && strlen(slash) > 0)
- s->filesize = strtoll(slash + 1, NULL, 10);
+ s->filesize = strtoull(slash + 1, NULL, 10);
}
if (s->seekable == -1 && (!s->is_akamai || s->filesize != 2147483647))
h->is_streamed = 0; /* we _can_ in fact seek */
@@ -799,8 +799,9 @@ static int process_line(URLContext *h, char *line, int line_count,
if ((ret = parse_location(s, p)) < 0)
return ret;
*new_location = 1;
- } else if (!av_strcasecmp(tag, "Content-Length") && s->filesize == -1) {
- s->filesize = strtoll(p, NULL, 10);
+ } else if (!av_strcasecmp(tag, "Content-Length") &&
+ s->filesize == UINT64_MAX) {
+ s->filesize = strtoull(p, NULL, 10);
} else if (!av_strcasecmp(tag, "Content-Range")) {
parse_content_range(h, p);
} else if (!av_strcasecmp(tag, "Accept-Ranges") &&
@@ -809,7 +810,7 @@ static int process_line(URLContext *h, char *line, int line_count,
h->is_streamed = 0;
} else if (!av_strcasecmp(tag, "Transfer-Encoding") &&
!av_strncasecmp(p, "chunked", 7)) {
- s->filesize = -1;
+ s->filesize = UINT64_MAX;
s->chunksize = 0;
} else if (!av_strcasecmp(tag, "WWW-Authenticate")) {
ff_http_auth_handle_header(&s->auth_state, tag, p);
@@ -833,7 +834,7 @@ static int process_line(URLContext *h, char *line, int line_count,
if (parse_cookie(s, p, &s->cookie_dict))
av_log(h, AV_LOG_WARNING, "Unable to parse '%s'\n", p);
} else if (!av_strcasecmp(tag, "Icy-MetaInt")) {
- s->icy_metaint = strtoll(p, NULL, 10);
+ s->icy_metaint = strtoull(p, NULL, 10);
} else if (!av_strncasecmp(tag, "Icy-", 4)) {
if ((ret = parse_icy(s, tag, p)) < 0)
return ret;
@@ -963,7 +964,7 @@ static int http_read_header(URLContext *h, int *new_location)
char line[MAX_URL_SIZE];
int err = 0;
- s->chunksize = -1;
+ s->chunksize = UINT64_MAX;
for (;;) {
if ((err = http_get_line(s, line, sizeof(line))) < 0)
@@ -997,10 +998,11 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
int post, err;
char headers[HTTP_HEADERS_SIZE] = "";
char *authstr = NULL, *proxyauthstr = NULL;
- int64_t off = s->off;
+ uint64_t off = s->off;
int len = 0;
const char *method;
int send_expect_100 = 0;
+ int ret;
/* send http header */
post = h->flags & AVIO_FLAG_WRITE;
@@ -1045,7 +1047,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
// server supports seeking by analysing the reply headers.
if (!has_header(s->headers, "\r\nRange: ") && !post && (s->off > 0 || s->end_off || s->seekable == -1)) {
len += av_strlcatf(headers + len, sizeof(headers) - len,
- "Range: bytes=%"PRId64"-", s->off);
+ "Range: bytes=%"PRIu64"-", s->off);
if (s->end_off)
len += av_strlcatf(headers + len, sizeof(headers) - len,
"%"PRId64, s->end_off - 1);
@@ -1091,7 +1093,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
if (s->headers)
av_strlcpy(headers + len, s->headers, sizeof(headers) - len);
- snprintf(s->buffer, sizeof(s->buffer),
+ ret = snprintf(s->buffer, sizeof(s->buffer),
"%s %s HTTP/1.1\r\n"
"%s"
"%s"
@@ -1107,6 +1109,14 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
av_log(h, AV_LOG_DEBUG, "request: %s\n", s->buffer);
+ if (strlen(headers) + 1 == sizeof(headers) ||
+ ret >= sizeof(s->buffer)) {
+ av_log(h, AV_LOG_ERROR, "overlong headers\n");
+ err = AVERROR(EINVAL);
+ goto done;
+ }
+
+
if ((err = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)
goto done;
@@ -1120,7 +1130,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
s->line_count = 0;
s->off = 0;
s->icy_data_read = 0;
- s->filesize = -1;
+ s->filesize = UINT64_MAX;
s->willclose = 0;
s->end_chunked_post = 0;
s->end_header = 0;
@@ -1152,6 +1162,34 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size)
{
HTTPContext *s = h->priv_data;
int len;
+
+ if (s->chunksize != UINT64_MAX) {
+ if (!s->chunksize) {
+ char line[32];
+ int err;
+
+ do {
+ if ((err = http_get_line(s, line, sizeof(line))) < 0)
+ return err;
+ } while (!*line); /* skip CR LF from last chunk */
+
+ s->chunksize = strtoull(line, NULL, 16);
+
+ av_log(h, AV_LOG_TRACE,
+ "Chunked encoding data size: %"PRIu64"'\n",
+ s->chunksize);
+
+ if (!s->chunksize)
+ return 0;
+ else if (s->chunksize == UINT64_MAX) {
+ av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n",
+ s->chunksize);
+ return AVERROR(EINVAL);
+ }
+ }
+ size = FFMIN(size, s->chunksize);
+ }
+
/* read bytes from input buffer first */
len = s->buf_end - s->buf_ptr;
if (len > 0) {
@@ -1160,15 +1198,13 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size)
memcpy(buf, s->buf_ptr, len);
s->buf_ptr += len;
} else {
- int64_t target_end = s->end_off ? s->end_off : s->filesize;
- if ((!s->willclose || s->chunksize < 0) &&
- target_end >= 0 && s->off >= target_end)
+ uint64_t target_end = s->end_off ? s->end_off : s->filesize;
+ if ((!s->willclose || s->chunksize == UINT64_MAX) && s->off >= target_end)
return AVERROR_EOF;
len = ffurl_read(s->hd, buf, size);
- if (!len && (!s->willclose || s->chunksize < 0) &&
- target_end >= 0 && s->off < target_end) {
+ if (!len && (!s->willclose || s->chunksize == UINT64_MAX) && s->off < target_end) {
av_log(h, AV_LOG_ERROR,
- "Stream ends prematurely at %"PRId64", should be %"PRId64"\n",
+ "Stream ends prematurely at %"PRIu64", should be %"PRIu64"\n",
s->off, target_end
);
return AVERROR(EIO);
@@ -1176,8 +1212,10 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size)
}
if (len > 0) {
s->off += len;
- if (s->chunksize > 0)
+ if (s->chunksize > 0) {
+ av_assert0(s->chunksize >= len);
s->chunksize -= len;
+ }
}
return len;
}
@@ -1231,25 +1269,6 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size)
return err;
}
- if (s->chunksize >= 0) {
- if (!s->chunksize) {
- char line[32];
-
- do {
- if ((err = http_get_line(s, line, sizeof(line))) < 0)
- return err;
- } while (!*line); /* skip CR LF from last chunk */
-
- s->chunksize = strtoll(line, NULL, 16);
-
- av_log(NULL, AV_LOG_TRACE, "Chunked encoding data size: %"PRId64"'\n",
- s->chunksize);
-
- if (!s->chunksize)
- return 0;
- }
- size = FFMIN(size, s->chunksize);
- }
#if CONFIG_ZLIB
if (s->compressed)
return http_buf_read_compressed(h, buf, size);
@@ -1257,17 +1276,17 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size)
read_ret = http_buf_read(h, buf, size);
if ( (read_ret < 0 && s->reconnect && (!h->is_streamed || s->reconnect_streamed) && s->filesize > 0 && s->off < s->filesize)
|| (read_ret == 0 && s->reconnect_at_eof && (!h->is_streamed || s->reconnect_streamed))) {
- int64_t target = h->is_streamed ? 0 : s->off;
+ uint64_t target = h->is_streamed ? 0 : s->off;
if (s->reconnect_delay > s->reconnect_delay_max)
return AVERROR(EIO);
- av_log(h, AV_LOG_INFO, "Will reconnect at %"PRId64" error=%s.\n", s->off, av_err2str(read_ret));
+ av_log(h, AV_LOG_INFO, "Will reconnect at %"PRIu64" error=%s.\n", s->off, av_err2str(read_ret));
av_usleep(1000U*1000*s->reconnect_delay);
s->reconnect_delay = 1 + 2*s->reconnect_delay;
seek_ret = http_seek_internal(h, target, SEEK_SET, 1);
if (seek_ret != target) {
- av_log(h, AV_LOG_ERROR, "Failed to reconnect at %"PRId64".\n", target);
+ av_log(h, AV_LOG_ERROR, "Failed to reconnect at %"PRIu64".\n", target);
return read_ret;
}
@@ -1322,10 +1341,11 @@ static int store_icy(URLContext *h, int size)
{
HTTPContext *s = h->priv_data;
/* until next metadata packet */
- int remaining = s->icy_metaint - s->icy_data_read;
+ uint64_t remaining;
- if (remaining < 0)
+ if (s->icy_metaint < s->icy_data_read)
return AVERROR_INVALIDDATA;
+ remaining = s->icy_metaint - s->icy_data_read;
if (!remaining) {
/* The metadata packet is variable sized. It has a 1 byte header
@@ -1439,7 +1459,7 @@ static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int fo
{
HTTPContext *s = h->priv_data;
URLContext *old_hd = s->hd;
- int64_t old_off = s->off;
+ uint64_t old_off = s->off;
uint8_t old_buf[BUFFER_SIZE];
int old_buf_size, ret;
AVDictionary *options = NULL;
@@ -1450,7 +1470,7 @@ static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int fo
((whence == SEEK_CUR && off == 0) ||
(whence == SEEK_SET && off == s->off)))
return s->off;
- else if ((s->filesize == -1 && whence == SEEK_END))
+ else if ((s->filesize == UINT64_MAX && whence == SEEK_END))
return AVERROR(ENOSYS);
if (whence == SEEK_CUR)
@@ -1605,7 +1625,7 @@ redo:
s->buf_ptr = s->buffer;
s->buf_end = s->buffer;
s->line_count = 0;
- s->filesize = -1;
+ s->filesize = UINT64_MAX;
cur_auth_type = s->proxy_auth_state.auth_type;
/* Note: This uses buffering, potentially reading more than the
diff --git a/libavformat/icodec.c b/libavformat/icodec.c
index 6ddb901b7e..bd83ef4c95 100644
--- a/libavformat/icodec.c
+++ b/libavformat/icodec.c
@@ -60,7 +60,7 @@ static int probe(AVProbeData *p)
offset = AV_RL32(p->buf + 18 + i * 16);
if (offset < 22)
return FFMIN(i, AVPROBE_SCORE_MAX / 4);
- if (offset + 8 > p->buf_size)
+ if (offset > p->buf_size - 8)
return AVPROBE_SCORE_MAX / 4 + FFMIN(i, 1);
if (p->buf[offset] != 40 && AV_RB64(p->buf + offset) != PNGSIG)
return FFMIN(i, AVPROBE_SCORE_MAX / 4);
@@ -105,6 +105,10 @@ static int read_header(AVFormatContext *s)
avio_skip(pb, 5);
ico->images[i].size = avio_rl32(pb);
+ if (ico->images[i].size <= 0) {
+ av_log(s, AV_LOG_ERROR, "Invalid image size %d\n", ico->images[i].size);
+ return AVERROR_INVALIDDATA;
+ }
ico->images[i].offset = avio_rl32(pb);
if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0)
@@ -170,8 +174,10 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
bytestream_put_le16(&buf, 0);
bytestream_put_le32(&buf, 0);
- if ((ret = avio_read(pb, buf, image->size)) < 0)
- return ret;
+ if ((ret = avio_read(pb, buf, image->size)) != image->size) {
+ av_packet_unref(pkt);
+ return ret < 0 ? ret : AVERROR_INVALIDDATA;
+ }
st->codec->bits_per_coded_sample = AV_RL16(buf + 14);
@@ -193,6 +199,13 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
return 0;
}
+static int ico_read_close(AVFormatContext * s)
+{
+ IcoDemuxContext *ico = s->priv_data;
+ av_freep(&ico->images);
+ return 0;
+}
+
AVInputFormat ff_ico_demuxer = {
.name = "ico",
.long_name = NULL_IF_CONFIG_SMALL("Microsoft Windows ICO"),
@@ -200,5 +213,6 @@ AVInputFormat ff_ico_demuxer = {
.read_probe = probe,
.read_header = read_header,
.read_packet = read_packet,
+ .read_close = ico_read_close,
.flags = AVFMT_NOTIMESTAMPS,
};
diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c
index 76bb3924b1..d733953a04 100644
--- a/libavformat/idroqdec.c
+++ b/libavformat/idroqdec.c
@@ -157,6 +157,9 @@ static int roq_read_packet(AVFormatContext *s,
chunk_size = AV_RL32(&preamble[2]) + RoQ_CHUNK_PREAMBLE_SIZE * 2 +
codebook_size;
+ if (chunk_size > INT_MAX)
+ return AVERROR_INVALIDDATA;
+
/* rewind */
avio_seek(pb, codebook_offset, SEEK_SET);
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d788232150..76b9c8d0c2 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -87,6 +87,7 @@ typedef const struct EbmlSyntax {
int list_elem_size;
int data_offset;
union {
+ int64_t i;
uint64_t u;
double f;
const char *s;
@@ -606,7 +607,7 @@ static const EbmlSyntax matroska_blockgroup[] = {
{ MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock, bin) },
{ MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock, duration) },
{ MATROSKA_ID_DISCARDPADDING, EBML_SINT, 0, offsetof(MatroskaBlock, discard_padding) },
- { MATROSKA_ID_BLOCKREFERENCE, EBML_SINT, 0, offsetof(MatroskaBlock, reference) },
+ { MATROSKA_ID_BLOCKREFERENCE, EBML_SINT, 0, offsetof(MatroskaBlock, reference), { .i = INT64_MIN } },
{ MATROSKA_ID_CODECSTATE, EBML_NONE },
{ 1, EBML_UINT, 0, offsetof(MatroskaBlock, non_simple), { .u = 1 } },
{ 0 }
@@ -977,6 +978,9 @@ static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
for (i = 0; syntax[i].id; i++)
switch (syntax[i].type) {
+ case EBML_SINT:
+ *(int64_t *) ((char *) data + syntax[i].data_offset) = syntax[i].def.i;
+ break;
case EBML_UINT:
*(uint64_t *) ((char *) data + syntax[i].data_offset) = syntax[i].def.u;
break;
@@ -3097,7 +3101,7 @@ static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska)
matroska->current_cluster_num_blocks = blocks_list->nb_elem;
i = blocks_list->nb_elem - 1;
if (blocks[i].bin.size > 0 && blocks[i].bin.data) {
- int is_keyframe = blocks[i].non_simple ? !blocks[i].reference : -1;
+ int is_keyframe = blocks[i].non_simple ? blocks[i].reference == INT64_MIN : -1;
uint8_t* additional = blocks[i].additional.size > 0 ?
blocks[i].additional.data : NULL;
if (!blocks[i].non_simple)
@@ -3135,7 +3139,7 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska)
blocks = blocks_list->elem;
for (i = 0; i < blocks_list->nb_elem; i++)
if (blocks[i].bin.size > 0 && blocks[i].bin.data) {
- int is_keyframe = blocks[i].non_simple ? !blocks[i].reference : -1;
+ int is_keyframe = blocks[i].non_simple ? blocks[i].reference == INT64_MIN : -1;
res = matroska_parse_block(matroska, blocks[i].bin.data,
blocks[i].bin.size, blocks[i].bin.pos,
cluster.timecode, blocks[i].duration,
@@ -3579,6 +3583,11 @@ static int webm_dash_manifest_read_header(AVFormatContext *s)
av_log(s, AV_LOG_ERROR, "Failed to read file headers\n");
return -1;
}
+ if (!s->nb_streams) {
+ matroska_read_close(s);
+ av_log(s, AV_LOG_ERROR, "No streams found\n");
+ return AVERROR_INVALIDDATA;
+ }
if (!matroska->is_live) {
buf = av_asprintf("%g", matroska->duration);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6b90d08ddc..b06e9c84ae 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -380,11 +380,11 @@ retry:
return ret;
} else if (!key && c->found_hdlr_mdta && c->meta_keys) {
uint32_t index = AV_RB32(&atom.type);
- if (index < c->meta_keys_count) {
+ if (index < c->meta_keys_count && index > 0) {
key = c->meta_keys[index];
} else {
av_log(c->fc, AV_LOG_WARNING,
- "The index of 'data' is out of range: %d >= %d.\n",
+ "The index of 'data' is out of range: %d < 1 or >= %d.\n",
index, c->meta_keys_count);
}
}
@@ -674,6 +674,8 @@ static int mov_read_hdlr(MOVContext *c, AVIOContext *pb, MOVAtom atom)
title_size = atom.size - 24;
if (title_size > 0) {
+ if (title_size > FFMIN(INT_MAX, SIZE_MAX-1))
+ return AVERROR_INVALIDDATA;
title_str = av_malloc(title_size + 1); /* Add null terminator */
if (!title_str)
return AVERROR(ENOMEM);
@@ -3899,7 +3901,7 @@ static int mov_read_uuid(MOVContext *c, AVIOContext *pb, MOVAtom atom)
0x9c, 0x71, 0x99, 0x94, 0x91, 0xe3, 0xaf, 0xac
};
- if (atom.size < sizeof(uuid) || atom.size == INT64_MAX)
+ if (atom.size < sizeof(uuid) || atom.size >= FFMIN(INT_MAX, SIZE_MAX))
return AVERROR_INVALIDDATA;
ret = avio_read(pb, uuid, sizeof(uuid));
@@ -4062,8 +4064,8 @@ static int mov_read_senc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
avio_rb32(pb); /* entries */
- if (atom.size < 8) {
- av_log(c->fc, AV_LOG_ERROR, "senc atom size %"PRId64" too small\n", atom.size);
+ if (atom.size < 8 || atom.size > FFMIN(INT_MAX, SIZE_MAX)) {
+ av_log(c->fc, AV_LOG_ERROR, "senc atom size %"PRId64" invalid\n", atom.size);
return AVERROR_INVALIDDATA;
}
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 69685cf890..db8f1f99a5 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -112,7 +112,7 @@ static int mpegps_probe(AVProbeData *p)
: AVPROBE_SCORE_EXTENSION / 2; // 1 more than .mpg
if ((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys &&
!pspack && p->buf_size > 2048 && vid + audio > invalid) /* PES stream */
- return (audio > 12 || vid > 3 + 2 * invalid) ? AVPROBE_SCORE_EXTENSION + 2
+ return (audio > 12 || vid > 6 + 2 * invalid) ? AVPROBE_SCORE_EXTENSION + 2
: AVPROBE_SCORE_EXTENSION / 2;
// 02-Penguin.flac has sys:0 priv1:0 pspack:0 vid:0 audio:1
@@ -138,7 +138,7 @@ typedef struct MpegDemuxContext {
static int mpegps_read_header(AVFormatContext *s)
{
MpegDemuxContext *m = s->priv_data;
- char buffer[7];
+ char buffer[7] = { 0 };
int64_t last_pos = avio_tell(s->pb);
m->header_state = 0xff;
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index e8f3889d1a..c85c30ddad 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2585,8 +2585,17 @@ static int mpegts_read_header(AVFormatContext *s)
packet_count[nb_pcrs] = nb_packets;
pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
nb_pcrs++;
- if (nb_pcrs >= 2)
- break;
+ if (nb_pcrs >= 2) {
+ if (pcrs[1] - pcrs[0] > 0) {
+ /* the difference needs to be positive to make sense for bitrate computation */
+ break;
+ } else {
+ av_log(ts->stream, AV_LOG_WARNING, "invalid pcr pair %"PRId64" >= %"PRId64"\n", pcrs[0], pcrs[1]);
+ pcrs[0] = pcrs[1];
+ packet_count[0] = packet_count[1];
+ nb_pcrs--;
+ }
+ }
} else {
finished_reading_packet(s, ts->raw_packet_size);
}
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index f4222fcab5..173a769ada 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -382,7 +382,7 @@ static int mxf_get_stream_index(AVFormatContext *s, KLVPacket *klv)
for (i = 0; i < s->nb_streams; i++) {
MXFTrack *track = s->streams[i]->priv_data;
/* SMPTE 379M 7.3 */
- if (!memcmp(klv->key + sizeof(mxf_essence_element_key), track->track_number, sizeof(track->track_number)))
+ if (track && !memcmp(klv->key + sizeof(mxf_essence_element_key), track->track_number, sizeof(track->track_number)))
return i;
}
/* return 0 if only one stream, for OP Atom files with 0 as track number */
@@ -826,7 +826,7 @@ static inline int mxf_read_utf16_string(AVIOContext *pb, int size, char** str, i
int ret;
size_t buf_size;
- if (size < 0)
+ if (size < 0 || size > INT_MAX/2)
return AVERROR(EINVAL);
buf_size = size + size / 2 + 1;
@@ -3012,7 +3012,7 @@ static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt)
if (mxf->nb_index_tables >= 1 && mxf->current_edit_unit < t->nb_ptses) {
pkt->dts = mxf->current_edit_unit + t->first_dts;
pkt->pts = t->ptses[mxf->current_edit_unit];
- } else if (track->intra_only) {
+ } else if (track && track->intra_only) {
/* intra-only -> PTS = EditUnit.
* let utils.c figure out DTS since it can be < PTS if low_delay = 0 (Sony IMX30) */
pkt->pts = mxf->current_edit_unit;
diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 8f3b44c3c5..7ecb42ce8f 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -643,6 +643,8 @@ static int ogg_get_length(AVFormatContext *s)
int64_t pts;
if (i < 0) continue;
pts = ogg_calc_pts(s, i, NULL);
+ if (s->streams[i]->duration == AV_NOPTS_VALUE)
+ continue;
if (pts != AV_NOPTS_VALUE && s->streams[i]->start_time == AV_NOPTS_VALUE && !ogg->streams[i].got_start) {
s->streams[i]->duration -= pts;
ogg->streams[i].got_start= 1;
diff --git a/libavformat/oggparsedaala.c b/libavformat/oggparsedaala.c
index 3651ca188b..9e98d49c8f 100644
--- a/libavformat/oggparsedaala.c
+++ b/libavformat/oggparsedaala.c
@@ -126,6 +126,7 @@ static int daala_header(AVFormatContext *s, int idx)
if (hdr->gpshift >= 32) {
av_log(s, AV_LOG_ERROR, "Too large gpshift %d (>= 32).\n",
hdr->gpshift);
+ hdr->gpshift = 0;
return AVERROR_INVALIDDATA;
}
hdr->gpmask = (1U << hdr->gpshift) - 1;
@@ -232,7 +233,7 @@ static int daala_packet(AVFormatContext *s, int idx)
os->lastpts = os->lastdts = daala_gptopts(s, idx, os->granule, NULL) - duration;
if(s->streams[idx]->start_time == AV_NOPTS_VALUE) {
s->streams[idx]->start_time = os->lastpts;
- if (s->streams[idx]->duration)
+ if (s->streams[idx]->duration != AV_NOPTS_VALUE)
s->streams[idx]->duration -= s->streams[idx]->start_time;
}
}
diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c
index c86b12713e..3440a501c4 100644
--- a/libavformat/oggparsespeex.c
+++ b/libavformat/oggparsespeex.c
@@ -76,6 +76,13 @@ static int speex_header(AVFormatContext *s, int idx) {
spxp->packet_size = AV_RL32(p + 56);
frames_per_packet = AV_RL32(p + 64);
+ if (spxp->packet_size < 0 ||
+ frames_per_packet < 0 ||
+ spxp->packet_size * (int64_t)frames_per_packet > INT32_MAX / 256) {
+ av_log(s, AV_LOG_ERROR, "invalid packet_size, frames_per_packet %d %d\n", spxp->packet_size, frames_per_packet);
+ spxp->packet_size = 0;
+ return AVERROR_INVALIDDATA;
+ }
if (frames_per_packet)
spxp->packet_size *= frames_per_packet;
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index e84e54a5b1..20f87c4024 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -102,6 +102,7 @@ static const AVOption avformat_options[] = {
{"codec_whitelist", "List of decoders that are allowed to be used", OFFSET(codec_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
{"format_whitelist", "List of demuxers that are allowed to be used", OFFSET(format_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
{"protocol_whitelist", "List of protocols that are allowed to be used", OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
+{"max_streams", "maximum number of streams", OFFSET(max_streams), AV_OPT_TYPE_INT, { .i64 = 1000 }, 0, INT_MAX, D },
{NULL},
};
diff --git a/libavformat/rsd.c b/libavformat/rsd.c
index dd1f3723d0..c773c0aa9e 100644
--- a/libavformat/rsd.c
+++ b/libavformat/rsd.c
@@ -84,8 +84,10 @@ static int rsd_read_header(AVFormatContext *s)
}
codec->channels = avio_rl32(pb);
- if (!codec->channels)
+ if (codec->channels <= 0 || codec->channels > INT_MAX / 36) {
+ av_log(s, AV_LOG_ERROR, "Invalid number of channels: %d\n", codec->channels);
return AVERROR_INVALIDDATA;
+ }
avio_skip(pb, 4); // Bit depth
codec->sample_rate = avio_rl32(pb);
diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c
index 0d693c27f7..cde0da78ce 100644
--- a/libavformat/rtmppkt.c
+++ b/libavformat/rtmppkt.c
@@ -235,6 +235,14 @@ static int rtmp_packet_read_one_chunk(URLContext *h, RTMPPacket *p,
if (hdr != RTMP_PS_TWELVEBYTES)
timestamp += prev_pkt[channel_id].timestamp;
+ if (prev_pkt[channel_id].read && size != prev_pkt[channel_id].size) {
+ av_log(NULL, AV_LOG_ERROR, "RTMP packet size mismatch %d != %d\n",
+ size,
+ prev_pkt[channel_id].size);
+ ff_rtmp_packet_destroy(&prev_pkt[channel_id]);
+ prev_pkt[channel_id].read = 0;
+ }
+
if (!prev_pkt[channel_id].read) {
if ((ret = ff_rtmp_packet_create(p, channel_id, type, timestamp,
size)) < 0)
diff --git a/libavformat/sbgdec.c b/libavformat/sbgdec.c
index 03cd9226c9..659dfc81ff 100644
--- a/libavformat/sbgdec.c
+++ b/libavformat/sbgdec.c
@@ -927,7 +927,7 @@ static void expand_timestamps(void *log, struct sbg_script *s)
}
}
if (s->start_ts == AV_NOPTS_VALUE)
- s->start_ts = s->opt_start_at_first ? s->tseq[0].ts.t : now;
+ s->start_ts = (s->opt_start_at_first && s->tseq) ? s->tseq[0].ts.t : now;
s->end_ts = s->opt_duration ? s->start_ts + s->opt_duration :
AV_NOPTS_VALUE; /* may be overridden later by -E option */
cur_ts = now;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index c9bc6f2376..f90aeb20c1 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -708,7 +708,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret;
for (i = 0; i < s->nb_streams; i++) {
st = s->streams[i];
- if (st->probe_packets)
+ if (st->probe_packets || st->request_probe > 0)
if ((err = probe_codec(s, st, NULL)) < 0)
return err;
av_assert0(st->request_probe <= 0);
@@ -2402,11 +2402,14 @@ static void update_stream_timings(AVFormatContext *ic)
if (ic->nb_programs) {
for (i = 0; i < ic->nb_programs; i++) {
p = ic->programs[i];
- if (p->start_time != AV_NOPTS_VALUE && p->end_time > p->start_time)
+ if (p->start_time != AV_NOPTS_VALUE &&
+ p->end_time > p->start_time &&
+ p->end_time - (uint64_t)p->start_time <= INT64_MAX)
duration = FFMAX(duration, p->end_time - p->start_time);
}
- } else
+ } else if (end_time >= start_time && end_time - (uint64_t)start_time <= INT64_MAX) {
duration = FFMAX(duration, end_time - start_time);
+ }
}
}
if (duration != INT64_MIN && duration > 0 && ic->duration == AV_NOPTS_VALUE) {
@@ -3725,9 +3728,7 @@ static void free_stream(AVStream **pst)
av_dict_free(&st->metadata);
av_freep(&st->probe_data.buf);
av_freep(&st->index_entries);
- av_freep(&st->codec->extradata);
- av_freep(&st->codec->subtitle_header);
- av_freep(&st->codec);
+ avcodec_free_context(&st->codec);
av_freep(&st->priv_data);
if (st->info)
av_freep(&st->info->duration_error);
@@ -3816,8 +3817,11 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
int i;
AVStream **streams;
- if (s->nb_streams >= INT_MAX/sizeof(*streams))
+ if (s->nb_streams >= FFMIN(s->max_streams, INT_MAX/sizeof(*streams))) {
+ if (s->max_streams < INT_MAX/sizeof(*streams))
+ av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter (%d), see the documentation if you wish to increase it\n", s->max_streams);
return NULL;
+ }
streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams));
if (!streams)
return NULL;
diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index d95596f6ed..a9ba03f557 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -804,6 +804,8 @@ static int w64_read_header(AVFormatContext *s)
chunk_key[4] = 0;
avio_read(pb, chunk_key, 4);
chunk_size = avio_rl32(pb);
+ if (chunk_size == UINT32_MAX)
+ return AVERROR_INVALIDDATA;
value = av_mallocz(chunk_size + 1);
if (!value)
diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
index 301c045b41..757cf8b030 100644
--- a/libavformat/webmdashenc.c
+++ b/libavformat/webmdashenc.c
@@ -428,6 +428,10 @@ static int parse_adaptation_sets(AVFormatContext *s)
char *p = w->adaptation_sets;
char *q;
enum { new_set, parsed_id, parsing_streams } state;
+ if (!w->adaptation_sets) {
+ av_log(s, AV_LOG_ERROR, "The 'adaptation_sets' option must be set.\n");
+ return AVERROR(EINVAL);
+ }
// syntax id=0,streams=0,1,2 id=1,streams=3,4 and so on
state = new_set;
while (p < w->adaptation_sets + strlen(w->adaptation_sets)) {
@@ -458,7 +462,11 @@ static int parse_adaptation_sets(AVFormatContext *s)
if (as->streams == NULL)
return AVERROR(ENOMEM);
as->streams[as->nb_streams - 1] = to_integer(p, q - p + 1);
- if (as->streams[as->nb_streams - 1] < 0) return -1;
+ if (as->streams[as->nb_streams - 1] < 0 ||
+ as->streams[as->nb_streams - 1] >= s->nb_streams) {
+ av_log(s, AV_LOG_ERROR, "Invalid value for 'streams' in adapation_sets.\n");
+ return AVERROR(EINVAL);
+ }
if (*q == '\0') break;
if (*q == ' ') state = new_set;
p = ++q;
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index 1474482275..5c0eb11374 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -248,19 +248,38 @@ static const AVClass imgutils_class = {
.parent_log_context_offset = offsetof(ImgUtils, log_ctx),
};
-int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
+int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
{
ImgUtils imgutils = {
.class = &imgutils_class,
.log_offset = log_offset,
.log_ctx = log_ctx,
};
+ int64_t stride = av_image_get_linesize(pix_fmt, w, 0);
+ if (stride <= 0)
+ stride = 8LL*w;
+ stride += 128*8;
- if ((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8)
- return 0;
+ if ((int)w<=0 || (int)h<=0 || stride >= INT_MAX || stride*(uint64_t)(h+128) >= INT_MAX) {
+ av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\n", w, h);
+ return AVERROR(EINVAL);
+ }
- av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\n", w, h);
- return AVERROR(EINVAL);
+ if (max_pixels < INT64_MAX) {
+ if (w*(int64_t)h > max_pixels) {
+ av_log(&imgutils, AV_LOG_ERROR,
+ "Picture size %ux%u exceeds specified max pixel count %"PRId64", see the documentation if you wish to increase it\n",
+ w, h, max_pixels);
+ return AVERROR(EINVAL);
+ }
+ }
+
+ return 0;
+}
+
+int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
+{
+ return av_image_check_size2(w, h, INT64_MAX, AV_PIX_FMT_NONE, log_offset, log_ctx);
}
int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar)
diff --git a/libavutil/imgutils.h b/libavutil/imgutils.h
index 23282a38fa..19f34deced 100644
--- a/libavutil/imgutils.h
+++ b/libavutil/imgutils.h
@@ -192,6 +192,20 @@ int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx);
/**
+ * Check if the given dimension of an image is valid, meaning that all
+ * bytes of the image can be addressed with a signed int.
+ *
+ * @param w the width of the picture
+ * @param h the height of the picture
+ * @param max_pixels the maximum number of pixels the user wants to accept
+ * @param pix_fmt the pixel format, can be AV_PIX_FMT_NONE if unknown.
+ * @param log_offset the offset to sum to the log level for logging with log_ctx
+ * @param log_ctx the parent logging context, it may be NULL
+ * @return >= 0 if valid, a negative error code otherwise
+ */
+int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx);
+
+/**
* Check if the given sample aspect ratio of an image is valid.
*
* It is considered invalid if the denominator is 0 or if applying the ratio
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 44f8c1ee47..00872a4b73 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -30,6 +30,10 @@
# define NDEBUG
#endif
+#if defined(DEBUG) && !defined(CHECKED)
+# define CHECKED
+#endif
+
#include <limits.h>
#include <stdint.h>
#include <stddef.h>
@@ -257,6 +261,16 @@ void avpriv_request_sample(void *avc,
# define ff_dlog(ctx, ...) do { if (0) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
#endif
+// For debuging we use signed operations so overflows can be detected (by ubsan)
+// For production we use unsigned so there are no undefined operations
+#ifdef CHECKED
+#define SUINT int
+#define SUINT32 int32_t
+#else
+#define SUINT unsigned
+#define SUINT32 uint32_t
+#endif
+
/**
* Clip and convert a double value into the long long amin-amax range.
* This function is needed because conversion of floating point to integers when
diff --git a/libavutil/mips/generic_macros_msa.h b/libavutil/mips/generic_macros_msa.h
index b1d18dd9d3..0a59619e7b 100644
--- a/libavutil/mips/generic_macros_msa.h
+++ b/libavutil/mips/generic_macros_msa.h
@@ -85,12 +85,12 @@
#else // !(__mips == 64)
#define LD(psrc) \
( { \
- uint8_t *psrc_m = (uint8_t *) (psrc); \
+ uint8_t *psrc_ld_m = (uint8_t *) (psrc); \
uint32_t val0_m, val1_m; \
uint64_t val_m = 0; \
\
- val0_m = LW(psrc_m); \
- val1_m = LW(psrc_m + 4); \
+ val0_m = LW(psrc_ld_m); \
+ val1_m = LW(psrc_ld_m + 4); \
\
val_m = (uint64_t) (val1_m); \
val_m = (uint64_t) ((val_m << 32) & 0xFFFFFFFF00000000); \
@@ -172,12 +172,12 @@
#else // !(__mips == 64)
#define LD(psrc) \
( { \
- uint8_t *psrc_m1 = (uint8_t *) (psrc); \
+ uint8_t *psrc_ld_m = (uint8_t *) (psrc); \
uint32_t val0_m, val1_m; \
uint64_t val_m = 0; \
\
- val0_m = LW(psrc_m1); \
- val1_m = LW(psrc_m1 + 4); \
+ val0_m = LW(psrc_ld_m); \
+ val1_m = LW(psrc_ld_m + 4); \
\
val_m = (uint64_t) (val1_m); \
val_m = (uint64_t) ((val_m << 32) & 0xFFFFFFFF00000000); \
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index 0821550bc8..69bf43466c 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -67,6 +67,7 @@ static uint32_t get_generic_seed(void)
uint8_t tmp[120];
struct AVSHA *sha = (void*)tmp;
clock_t last_t = 0;
+ clock_t last_td = 0;
static uint64_t i = 0;
static uint32_t buffer[512] = { 0 };
unsigned char digest[20];
@@ -86,11 +87,12 @@ static uint32_t get_generic_seed(void)
for (;;) {
clock_t t = clock();
-
- if (last_t == t) {
- buffer[i & 511]++;
+ if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) >= t) {
+ last_td = t - last_t;
+ buffer[i & 511] = 1664525*buffer[i & 511] + 1013904223 + (last_td % 3294638521U);
} else {
- buffer[++i & 511] += (t - last_t) % 3294638521U;
+ last_td = t - last_t;
+ buffer[++i & 511] += last_td % 3294638521U;
if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8)
break;
}
diff --git a/libavutil/softfloat.h b/libavutil/softfloat.h
index 4b895f014b..b4fce57906 100644
--- a/libavutil/softfloat.h
+++ b/libavutil/softfloat.h
@@ -27,7 +27,7 @@
#include "avassert.h"
#include "softfloat_tables.h"
-#define MIN_EXP -126
+#define MIN_EXP -149
#define MAX_EXP 126
#define ONE_BITS 29
@@ -110,8 +110,15 @@ static inline av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b){
* @return Will not be more denormalized than a.
*/
static inline av_const SoftFloat av_div_sf(SoftFloat a, SoftFloat b){
+ int64_t temp = (int64_t)a.mant * (1<<(ONE_BITS+1));
+ temp /= b.mant;
a.exp -= b.exp;
- a.mant = ((int64_t)a.mant<<(ONE_BITS+1)) / b.mant;
+ a.mant = temp;
+ while (a.mant != temp) {
+ temp /= 2;
+ a.exp--;
+ a.mant = temp;
+ }
a = av_normalize1_sf(a);
if (!a.mant || a.exp < MIN_EXP)
return FLOAT_0;
@@ -155,7 +162,7 @@ static inline av_const SoftFloat av_sub_sf(SoftFloat a, SoftFloat b){
*/
static inline av_const SoftFloat av_int2sf(int v, int frac_bits){
int exp_offset = 0;
- if(v == INT_MIN){
+ if(v <= INT_MIN + 1){
exp_offset = 1;
v>>=1;
}
@@ -214,12 +221,12 @@ static av_unused void av_sincos_sf(int a, int *s, int *c)
int st, ct;
idx = a >> 26;
- sign = (idx << 27) >> 31;
+ sign = (int32_t)((unsigned)idx << 27) >> 31;
cv = av_costbl_1_sf[idx & 0xf];
cv = (cv ^ sign) - sign;
idx -= 8;
- sign = (idx << 27) >> 31;
+ sign = (int32_t)((unsigned)idx << 27) >> 31;
sv = av_costbl_1_sf[idx & 0xf];
sv = (sv ^ sign) - sign;
diff --git a/libswresample/resample.c b/libswresample/resample.c
index d410432658..a19af17516 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -295,6 +295,14 @@ fail:
return 0;
}
+static void resample_free(ResampleContext **cc){
+ ResampleContext *c = *cc;
+ if(!c)
+ return;
+ av_freep(&c->filter_bank);
+ av_freep(cc);
+}
+
static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
double cutoff0, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta,
double precision, int cheby)
@@ -306,6 +314,7 @@ static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_r
if (!c || c->phase_shift != phase_shift || c->linear!=linear || c->factor != factor
|| c->filter_length != FFMAX((int)ceil(filter_size/factor), 1) || c->format != format
|| c->filter_type != filter_type || c->kaiser_beta != kaiser_beta) {
+ resample_free(&c);
c = av_mallocz(sizeof(*c));
if (!c)
return NULL;
@@ -375,13 +384,6 @@ error:
return NULL;
}
-static void resample_free(ResampleContext **c){
- if(!*c)
- return;
- av_freep(&(*c)->filter_bank);
- av_freep(c);
-}
-
static int set_compensation(ResampleContext *c, int sample_delta, int compensation_distance){
c->compensation_distance= compensation_distance;
if (compensation_distance)
diff --git a/libswscale/swscale-test.c b/libswscale/swscale-test.c
index 4d8d08bd1a..b1a526dcac 100644
--- a/libswscale/swscale-test.c
+++ b/libswscale/swscale-test.c
@@ -307,10 +307,10 @@ static int fileTest(uint8_t *ref[4], int refStride[4], int w, int h, FILE *fp,
struct Results r;
enum AVPixelFormat srcFormat;
char srcStr[12];
- int srcW, srcH;
+ int srcW = 0, srcH = 0;
enum AVPixelFormat dstFormat;
char dstStr[12];
- int dstW, dstH;
+ int dstW = 0, dstH = 0;
int flags;
int ret;
diff --git a/tests/ref/fate/vp5 b/tests/ref/fate/vp5
index 0e601ba811..f044567fd9 100644
--- a/tests/ref/fate/vp5
+++ b/tests/ref/fate/vp5
@@ -245,4 +245,4 @@
0, 243, 243, 1, 233472, 0x6f530ac6
0, 244, 244, 1, 233472, 0x94f7466c
0, 245, 245, 1, 233472, 0xa8c1d365
-0, 246, 246, 1, 233472, 0xedcff050
+0, 246, 246, 1, 233472, 0xbf73f1b7
diff --git a/tools/ismindex.c b/tools/ismindex.c
index dfef118653..363b7eead7 100644
--- a/tools/ismindex.c
+++ b/tools/ismindex.c
@@ -375,7 +375,7 @@ static int read_tfra(struct Tracks *tracks, int start_index, AVIOContext *f)
track->duration -
track->offsets[track->chunks - 1].time;
}
- // Now try and read the actual durations from the trun sample data.
+ // Now try to read the actual durations from the trun sample data.
for (i = 0; i < track->chunks; i++) {
int64_t duration = read_moof_duration(f, track->offsets[i].offset);
if (duration > 0 && llabs(duration - track->offsets[i].duration) > 3) {
diff --git a/tools/zmqsend.c b/tools/zmqsend.c
index d47bf216b4..6148bd623c 100644
--- a/tools/zmqsend.c
+++ b/tools/zmqsend.c
@@ -53,7 +53,7 @@ int main(int argc, char **argv)
{
AVBPrint src;
char c, *src_buf, *recv_buf;
- int recv_buf_size, ret;
+ int recv_buf_size, ret = 0;
void *zmq_ctx, *socket;
const char *bind_address = "tcp://localhost:5555";
const char *infilename = NULL;