diff --git a/Changelog b/Changelog index e83a00e35c..f88d35aafe 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,512 @@ Entries are sorted chronologically from oldest to youngest within each release, releases are sorted from youngest to oldest. +version 7.0.3: + doc/t2h: Support texinfo 7.1 and 7.2 pretest + avformat/iamf_parse: ensure there's at most one of each parameter types in audio elements + avformat/iamf_parse: add missing constrains for num_parameters in audio_element_oub() + avformat/iamf_parse: add missing av_free() call on failure path + avformat/iamf_writer: ensure the stream groups are not empty + avformat/iamf_writer: fix setting num_samples_per_frame for OPUS + avformat/iamf_parse: fix setting duration for the last subblock in a parameter definition + avformat/iamf_parse: add checks to parameter definition durations + avformat/iamfdec: don't set individual streams as dependent + avformat/iff: Check that we have a stream in read_dst_frame() + avformat/mlvdec: fix size checks + avformat/wavdec: Fix overflow of intermediate in block_align check + avformat/mxfdec: Check edit unit for overflow in mxf_set_current_edit_unit() + avformat/hls: Fix twitter + libavformat/hls: Be more restrictive on mpegts extensions + avformat/hls: .ts is always ok even if its a mov/mp4 + avcodec/h263dec: Check against previous dimensions instead of coded + avformat/hls: Print input format in error message + avformat/hls: Be more picky on extensions + avformat/mxfdec: Check avio_read() success in mxf_decrypt_triplet() + avcodec/huffyuvdec: Initialize whole output for decode_gray_bitstream() + avformat/iamf_reader: Initialize padding and check read in ff_iamf_read_packet() + avformat/ipmovie: Check signature_buffer read + avformat/wtvdec: Initialize buf + avcodec/cbs_vp9: Initialize VP9RawSuperframeIndex + avformat/vqf: Propagate errors from add_metadata() + avformat/vqf: Check avio_read() in add_metadata() + avformat/dashdec: Check whitelist + avutil/avstring: dont mess with NULL pointers in av_match_list() + avfilter/vf_v360: Fix NULL pointer use + avcodec/mpegvideo_enc: Check FLV1 resolution limits + avcodec/ffv1enc: Fix handling of 32bit unsigned symbols + avformat/mov: Factorize sanity check out + avcodec/vc1dec: Clear block_index in vc1_decode_reset() + avcodec/aacsbr_template: Clear n_q on error + avformat/iamf_parse: Check output_channel_count + avcodec/osq: Fixes several undefined overflows in do_decode() + swscale/output: Fix undefined overflow in yuv2rgba64_full_X_c_template() + avfilter/af_pan: Fix sscanf() use + avfilter/vf_grayworld: Use the correct pointer for av_log() + avfilter/vf_addroi: Add missing NULL termination to addroi_var_names[]() + avcodec/get_buffer: Use av_buffer_mallocz() for audio same as its done for video + avformat/jpegxl_anim_dec: clear buffer padding + avformat/rmdec: check that buf if completely filled + avcodec/cfhdenc: Clear dwt_tmp + avcodec/hapdec: Clear tex buffer + avformat/mxfdec: Check that key was read sucessfull + avformat/rpl: Fix check for negative values + avformat/mlvdec: Check avio_read() + avcodec/utils: Fix block align overflow for ADPCM_IMA_WAV + avformat/matroskadec: Check pre_ns for overflow + tools/target_dec_fuzzer: Adjust threshold for EACMV + tools/target_dec_fuzzer: Adjust threshold for MVC1 + tools/target_dec_fuzzer: Adjust Threshold for indeo5 + avutil/timecode: Avoid fps overflow in av_timecode_get_smpte_from_framenum() + avcodec/webp: Check ref_x/y + avcodec/ilbcdec: Initialize tempbuff2 + avformat/qcp: Check for read failure in header + avcodec/eatgq: Check bytestream2_get_buffer() for failure + avformat/dxa: check bpc + swscale/slice: clear allocated memory in alloc_lines() + avcodec/h2645_parse: Ignore NAL with nuh_layer_id == 63 + avformat/iamf_parse: reject ambisonics mode > 1 + avcodec/mjpegdec: Disallow progressive bayer images + avformat/icodec: fix integer overflow with nb_pal + doc/developer: Document relationship between git accounts and MAINTAINERS + doc/infra: Document trac backup system + doc/infra: Document gitolite + avformat/vividas: Check avio_read() for failure + avformat/ilbc: Check avio_read() for failure + avformat/nistspheredec: Clear buffer + avformat/mccdec: Initialize and check rate.den + avformat/rpl: check channels + INSTALL: explain the circular dependency issue and solution + avformat/mpegts: Initialize predefined_SLConfigDescriptor_seen + avformat/mxfdec: Fix overflow in midpoint computation + swscale/output: used unsigned for bit accumulation + avcodec/rangecoder: only perform renorm check/loop for callers that need it + avcodec/ffv1dec: Fix end computation with ec=2 + avcodec/ffv1enc: Prevent generation of files with broken slices + avformat/matroskadec: Check desc_bytes so bits fit in 64bit + avformat/mov: Avoid overflow in dts + avcodec/ffv1enc: Correct error message about unsupported version + avcodec/ffv1enc: Slice combination is unsupported + avcodec/ffv1enc: 2Pass mode is not possible with golomb coding + avcodec/ffv1enc: Fix >8bit context size + avcodec/xan: Add basic input size check + avcodec/imm4: Check input size + avcodec/svq3: Check for minimum size input + avcodec/eacmv: Check input size for intra frames + tools/target_dec_fuzzer: Adapt threshold for RASC + avcodec/encode: Check bitrate + avcodec/cbs_h266_syntax_template: Check bit depth with range extension + avcodec/osq: use unsigned for decorrelation + avcodec/jfdctint_template: use unsigned z* in row_fdct() + avformat/asf: Check picsize + avcodec/osq: Treat sum = 0 as k = 0 + avformat/mxfdec: Check timecode for overflow + avformat/mxfdec: More offset_temp checks + avformat/flvdec: Free metaVideoColor + swscale/output: Fix undefined integer overflow in yuv2rgba64_2_c_template() + swscale/swscale: Use unsigned operation to avoid undefined behavior + avcodec/vc2enc: basic sanity check on slice_max_bytes + avformat/mvdec: Check if name was fully read + avcodec/wmavoice: Do not use uninitialized pitch[0] + avformat/argo_brp: Check that ASF chunk header is completely read + avcodec/notchlc: Check bytes left before reading + avcodec/vc1_block: propagate error codes + avformat/apetag: Check APETAGEX + avcodec/magicyuvenc: better slice height + avcodec/avcodec: Warn about data returned from get_buffer*() + avformat/av1dec: Better fix for 70872/clusterfuzz-testcase-minimized-ffmpeg_dem_OBU_fuzzer-6005782487826432 + avcodec/apac: Fix discards ‘const’ qualifier + avcodec/alsdec: clear last_acf_mantissa + avcodec/aic: Clear slice_data + avcodec/vc1dec: Clear mb_type_base and ttblk_base + avcodec/shorten: clear padding + avformat/mpeg: Check an avio_read() for failure + avcodec/apac: Clean padding space + avcodec/mvha: Clear remaining space after inflate() + bsf/media100_to_mjpegb: Clear output buffer padding + avformat/iamfdec: Check nb_layers before dereferencing layer + avformat/av1dec: Check bits left before get_leb128() + avformat/segafilm: Set keyframe + avcodec/sga: av_assert1 check init_get_bits8() + tools/target_dec_fuzzer: Check that FFv1 doesnt leave uninitialized memory in its buffers + avdevice/dshow: Initialize 2 pointers + avcodec/dxva2: initialize hr in ff_dxva2_common_end_frame() + avcodec/dxva2: initialize validate + avcodec/dxva2: Initialize ConfigBitstreamRaw + avcodec/dxva2: Initialize dxva_size and check it + avfilter/vf_xfade: Compute w2, h2 with float + avfilter/vf_v360: Assert that vf was initialized + avfilter/vf_tonemap_opencl: Dereference after NULL check + avfilter/af_surround: Check output format + avfilter/vf_xfade_opencl: Check ff_inlink_consume_frame() for failure + avformat/lmlm4: Eliminate some AVERROR(EIO) + tools/target_dec_fuzzer: Use av_buffer_allocz() to avoid missing slices to have unpredictable content + avformat/wtvdec: Check length of read mpeg2_descriptor + avformat/wtvdec: clear sectors + avcodec/parser: ensure input padding is zeroed + avformat/jpegxl_anim_dec: ensure input padding is zeroed + avformat/img2dec: Clear padding data after EOF + avformat/wavdec: Check if there are 16 bytes before testing them + avformat/mov: (v4) fix get_eia608_packet + configure: Improve the check for the rsync --contimeout option + rtmpproto: Avoid rare crashes in the fail: codepath in rtmp_open + lavc/aarch64: Fix ff_pred16x16_plane_neon_10 + lavc/aarch64: Fix ff_pred8x8_plane_neon_10 + vp9: recon: Use emulated edge to prevent buffer overflows + arm: vp9mc: Load only 12 pixels in the 4 pixel wide horizontal filter + aarch64: vp9mc: Load only 12 pixels in the 4 pixel wide horizontal filter + avfilter/f_loop: fix aloop activate logic + avfilter/f_loop: fix length of aloop leftover buffer + avcodec/jpegxl_parser: fix reading lz77-pair as initial entropy symbol + avcodec/jpegxl_parser: check entropy_decoder_read_symbol return value + fftools/ffplay: fix crash when vk renderer is null + avutil/wchar_filename: re-introduce explicit cast of void* to char* + avcodec/libx265: unbreak build for X265_BUILD >= 213 + avutil/iamf: fix doxygen + avformat/mov_chan: add extra checks to channel description count + lavc/hevcdec: set per-CTB filter parameters for WPP + lavc/hevc: check framerate num/den to be strictly positive + lavc/libx265: unbreak build for X265_BUILD >= 210 + avformat/libzmq: fix check for zmq protocol prefix + configure: improve check for POSIX ioctl + configure: restore autodetection of v4l2 and fbdev + avformat/iamf_parse: Fix return of uninitialized value + avformat/iamf_parse: use get_bits_long() to read the remaining AAC extradata bits + avformat/iamf_parse: fix parsing AAC DecoderConfigDescriptor + avformat/isom: make parameters used for loging a pointer to void + avformat/iamf_parse: clear padding + avformat/hlsenc: correctly reset subtitle stream counter per-varstream + libavcodec/arm/mlpdsp_armv5te: fix label format to work with binutils 2.43 + avformat/iamf_parse: ignore Audio Elements with an unsupported type + lavc/vaapi_av1: Avoid sending the same slice buffer multiple times + lavc/vaapi_decode: Make it possible to send multiple slice params buffers + avformat/mov: fix track handling when mixing IAMF and video tracks + +version 7.0.2: + avcodec/snow: Fix off by 1 error in run_buffer + avcodec/utils: apply the same alignment to YUV410 as we do to YUV420 for snow + avformat/iamf_parse: Check for 0 samples + swscale: [loongarch] Fix checkasm-sw_yuv2rgb failure. + avcodec/aacps_tablegen_template: don't redefine CONFIG_HARDCODED_TABLES + avutil/hwcontext_vaapi: use the correct type for VASurfaceAttribExternalBuffers.buffers + avcodec/pcm-bluray/dvd: Use correct pointer types on BE + avcodec/pngenc: fix sBIT writing for indexed-color PNGs + avcodec/pngdec: use 8-bit sBIT cap for indexed PNGs per spec + avformat/mov: check that child boxes of trak are only present inside it + avformat/mov: check that sample and chunk count is 1 for HEIF + avcodec/videotoolboxenc: Fix bitrate doesn't work as expected + avdevice/dshow: Don't skip audio devices if no video device is present + avcodec/hdrenc: Allocate more space + avcodec/cfhdenc: Height of 16 is not supported + avcodec/cfhdenc: Allocate more space + avcodec/osq: fix integer overflow when applying factor + avcodec/osq: avoid using too large numbers for shifts and integers in update_residue_parameter() + avcodec/vaapi_encode: Check hwctx + avcodec/proresdec: Consider negative bits left + avcodec/alsdec: Clear shift_value + avcodec/hevc/hevcdec: Do not allow slices to depend on failed slices + avformat/mov: add an EOF check in IPRP + avfilter/vf_xfade: Check ff_inlink_consume_frame() for failure + avutil/slicethread: Check pthread_*_init() for failure + avutil/frame: Check log2_crop_align + avutil/buffer: Check ff_mutex_init() for failure + avformat/xmv: Check this_packet_size + avformat/webpenc: Check filesize in trailer + avformat/ty: rec_size seems to only need 32bit + avformat/tty: Check avio_size() + avformat/siff: Basic pkt_size check + avformat/sauce: Check avio_size() for failure + avformat/sapdec: Check ffurl_get_file_handle() for error + avformat/nsvdec: Check asize for PCM + avformat/mp3dec: Check header_filesize + avformat/mp3dec; Check for avio_size() failure + avformat/mov: Use 64bit for str_size + avformat/mm: Check length + avformat/hnm: Check *chunk_size + avformat/hlsenc: Check ret + avformat/bintext: Check avio_size() return + avformat/asfdec_o: Check size of index object + avfilter/vf_scale: Check ff_scale_adjust_dimensions() for failure + avfilter/scale_eval: Use 64bit, check values in ff_scale_adjust_dimensions() + avfilter/vf_lut3d: Check av_scanf() + avfilter/vf_elbg: Use unsigned for shifting into the top bit + avfilter/vf_premultiply: Use AV_PIX_MAX_PLANES + avfilter/vf_deshake_opencl: Ensure that the first iteration initializes the best variables + avformat/iamf_parse: Check for negative sample sizes + swscale/output: Fix integer overflows in yuv2rgba64_X_c_template + avformat/mxfdec: Reorder elements of expression in bisect loop + avutil/timecode: Use a 64bit framenum internally + avcodec/pnmdec: Use 64bit for input size check + avformat/mov: Check extradata in mov_read_iacb() + avcodec/mpeg12enc: Use av_rescale() in vbv_buffer_size computation + avcodec/utvideoenc: Use unsigned shift to build flags + avcodec/j2kenc: Merge dwt_norm into lambda + avcodec/vc2enc: Fix overflows with storing large values + avcodec/mpegvideo_enc: Do not duplicate pictures on shifting + avdevice/dshow_capture: Fix error handling in ff_dshow_##prefix##_Create() + avcodec/tiff: Check value on positive signed targets + avfilter/vf_convolution_opencl: Assert that the filter name is one of the filters + avfilter/vf_bm3d: Dont round MSE2SSE to an integer + avdevice/dshow: Remove NULL check on pin + avdevice/dshow: check ff_dshow_pin_ConnectionMediaType() for failure + avdevice/dshow: Check device_filter_unique_name before use + avdevice/dshow: Cleanup also on av_log case + avdevice/dshow_filter: Use wcscpy_s() + avcodec/flac_parser: Assert that we do not overrun the link_penalty array + avcodec/osq: avoid signed overflow in downsample path + avcodec/pixlet: Simplify pfx computation + avcodec/motion_est: Fix score squaring overflow + avcodec/mlpenc: Use 64 for ml, mr + avcodec/loco: Check loco_get_rice() for failure + avcodec/loco: check get_ur_golomb_jpegls() for failure + avcodec/leaddec: Check init_get_bits8() for failure + avcodec/imm4: check cbphi for error + avcodec/iff: Use signed count + avcodec/golomb: Assert that k is in the supported range for get_ur/sr_golomb() + avcodec/golomb: Document return for get_ur_golomb_jpegls() and get_sr_golomb_flac() + avcodec/dxv: Fix type in get_opcodes() + avcodec/cri: Check length + avcodec/xsubdec: Check parse_timecode() + avutil/imgutils: av_image_check_size2() ensure width and height fit in 32bit + avfilter/vf_tiltandshift: Free dst on error + doc/examples/mux: remove nop + avcodec/proresenc_kostya: use unsigned alpha for rotation + avformat/rtpenc_rfc4175: Use 64bit in computation if copy_offset + avformat/rtmpproto: Use AV_DICT_MATCH_CASE instead of litteral number + avformat/rtmppkt: Simplify and deobfuscate amf_tag_skip() slightly + avformat/rmdec: use 64bit for audio_framesize checks + avutil/wchar_filename: Correct sizeof + avutil/hwcontext_d3d11va: correct sizeof IDirect3DSurface9 + avutil/hwcontext_d3d11va: Free AVD3D11FrameDescriptor on error + avutil/hwcontext_d3d11va: correct sizeof AVD3D11FrameDescriptor + avcodec/vvc/refs: Use unsigned mask + doc/examples/vaapi_encode: Try to check fwrite() for failure + avformat/usmdec: Initialize value + avformat/tls_schannel: Initialize ret + avformat/subfile: Assert that whence is a known case + avformat/subfile: Merge if into switch() + avformat/rtsp: Check that lower transport is handled in one of the if() + avformat/rtsp: initialize reply1 + avformat/rtsp: use < 0 for error check + avformat/rtpenc_vc2hq: Check sizes + avfilter/af_aderivative: Free out on error + swscale/swscale: Use ptrdiff_t for linesize computations + avfilter/af_amerge: Cleanup on av_channel_layout_copy() failure + avfilter/af_afir: Assert format + avfilter/af_afftdn: Assert format + avfilter/af_pan: check nb_output_channels before use + cbs_av1: Reject thirty-two zero bits in uvlc code + avfilter/af_mcompand: compute half frequency in double + avfilter/af_channelsplit: Assert that av_channel_layout_channel_from_index() succeeds + avfilter/af_aresample: Cleanup on av_channel_layout_copy() failure + tools/coverity: Phase 1 study of anti-halicogenic for coverity av_rescale() + avfilter/vf_avgblur: Check plane instead of AVFrame + avfilter/drawutils: Fix depthb computation + avfilter/avf_showcwt: Check av_parse_video_rate() for failure + avformat/rdt: Check pkt_len + avformat/mpeg: Check len in mpegps_probe() + avformat/mxfenc: resurrects the error print + avdevice/dshow: Check ICaptureGraphBuilder2_SetFiltergraph() for failure + avcodec/mfenc: check IMFSample_ConvertToContiguousBuffer() for failure + avcodec/vc1_loopfilter: Factor duplicate code in vc1_b_h_intfi_loop_filter() + avcodec/vvc/ctu: Remove dead ret check + avcodec/vvc/dec: Remove constant eos_at_start + avformat/img2dec: assert no pipe on ts_from_file + avcodec/cbs_jpeg: Try to move the read entity to one side in a test + fftools/ffplay: Check vulkan_params + fftools/ffmpeg_enc: Initialize Decoder + fftools/ffmpeg_enc: Initialize fd + fftools/ffmpeg_enc: simplify opaque_ref check + avformat/mov: Check edit list for overflow + fftools/ffmpeg: Check read() for failure + avcodec/vvc/dec: Check ff_init_cabac_decoder() for failure + MAINTAINERS: Add Timo Rothenpieler to server admins + swscale/output: Avoid undefined overflow in yuv2rgb_write_full() + swscale/output: alpha can become negative after scaling, use multiply + avcodec/targaenc: Allocate space for the palette + avcodec/r210enc: Use av_rescale for bitrate + avcodec/jfdctint_template: Fewer integer anomalies + avcodec/snowenc: MV limits due to mv_penalty table size + tools/target_dec_fuzzer: Adjust threshold for MV30 + tools/target_dec_fuzzer: Adjust threshold for jpeg2000 + avformat/mxfdec: Check container_ul->desc before use + avcodec/libvpxenc: Cleanup on error + MAINTAINERS: Update the entries for the release maintainer for FFmpeg + doc/developer: Provide information about git send-email and gmail + avfilter/vf_rotate: Check ff_draw_init2() return value + avformat/mov: Use int64_t in intermediate for corrected_dts + avformat/mov: Use 64bit in intermediate for current_dts + avformat/matroskadec: Assert that num_levels is non negative + avformat/libzmq: Check av_strstart() + avformat/img2dec: Little JFIF / Exif cleanup + avformat/img2dec: Move DQT after unrelated if() + avformat/imfdec: Simplify get_next_track_with_minimum_timestamp() + avdevice/xcbgrab: Check sscanf() return + fftools/cmdutils: Add protective () to FLAGS + avformat/sdp: Check before appending "," + avcodec/libx264: Check init_get_bits8() return code + avcodec/ilbcdec: Remove dead code + avcodec/vp8: Check cond init + avcodec/vp8: Check mutex init + avcodec/proresenc_anatoliy: Assert that AV_PROFILE_UNKNOWN is replaced + avcodec/pcm-dvdenc: 64bit pkt-size + avcodec/notchlc: Check init_get_bits8() for failure + avcodec/tests/dct: Use 64bit in intermediate for error computation + avcodec/scpr3: Check add_dec() for failure + avcodec/rv34: assert that size is not 0 in rv34_gen_vlc_ext() + avcodec/wavpackenc: Use unsigned for potential 31bit shift + avcodec/vvc/mvs: Initialize mvf + avcodec/tests/jpeg2000dwt: Use 64bit in comparission + avcodec/tests/jpeg2000dwt: Use 64bit in err2 computation + avformat/fwse: Remove always false expression + avcodec/sga: Make it clear that the return is intentionally not checked + avformat/asfdec_f: Use 64bit for preroll computation + avformat/argo_asf: Use 64bit in offset intermediate + avformat/ape: Use 64bit for final frame size + avformat/ac4dec: Check remaining space in ac4_probe() + avdevice/pulse_audio_enc: Use av_rescale() to avoid integer overflow + avcodec/vlc: Cleanup on multi table alloc failure in ff_vlc_init_multi_from_lengths() + avcodec/tiff: Assert init_get_bits8() success in unpack_gray() + avcodec/tiff: Assert init_get_bits8() success in horizontal_fill() + tools/decode_simple: Check avcodec_send_packet() for errors on flushing + swscale/yuv2rgb: Use 64bit for brightness computation + swscale/x86/swscale: use a clearer name for INPUT_PLANER_RGB_A_FUNC_CASE + avutil/tests/opt: Check av_set_options_string() for failure + avutil/tests/dict: Check av_dict_set() before get for failure + avdevice/dshow: fix badly indented line + avformat/demux: resurrect dead stores + avcodec/tests/bitstream_template: Assert bits_init8() return + tools/enc_recon_frame_test: Assert that av_image_get_linesize() succeeds + avformat/iamf_writer: disallow Opus extradata with mapping family other than 0 + avformat/iamf_parse: sanitize audio_roll_distance values + avformat/iamf: byteswap values in OpusHeader + avformat/iamf: rename Codec Config seek_preroll to audio_roll_distance + avformat/iamf_writer: fix coded audio_roll_distance values + avformat/iamf_writer: fix PCM endian-ness flag + avformat/movenc: fix channel count and samplerate fields for IAMF tracks + avformat/iamf_parse: keep substream count consistent + avformat/iamf_parse: add missing padding to AAC extradata + avformat/iamf_parse: 0 layers are not allowed + avformat/iamf_parse: consider nb_substreams when accessing substreams array + avformat/iamf_parse: Remove dead case + avcodec/png: more informative error message for invalid sBIT size + avcodec/pngdec: avoid erroring with sBIT on indexed-color images + avfilter/vf_tiltandshift: fix buffer offset for yuv422p input + avutil/timestamp: avoid possible FPE when 0 is passed to av_ts_make_time_string2() + avformat/mov: add more checks for infe atom size + avformat/mov: check for EOF inside the infe list parsing loop + avformat/mov: check extent_offset calculation for overflow + avformat/mov: check that iloc offset values fit on an int64_t + avcodec/pngenc: fix mDCv typo + avcodec/pngdec: fix mDCv typo + avcodec/nvenc: fix segfault in intra-only mode + avdevice/avfoundation: add external video devices + aarch64: Add OpenBSD runtime detection of dotprod and i8mm using sysctl + fftools/ffplay_renderer: use correct NULL value for Vulkan type + qsv: Initialize impl_value + avutil/hwcontext_qsv: fix GCC 14.1 warnings + avcodec/mediacodecenc: workaround the alignment requirement for H.265 + avcodec/mediacodecenc: workaround the alignment requirement only for H.264 + lavc/lpc: fix off-by-one in R-V V compute_autocorr + lavc/vp9: reset segmentation fields when segmentation isn't enabled + configure: enable ffnvcodec, nvenc, nvdec for FreeBSD + lavc/sbrdsp: fix potential overflow in noise table + +version 7.0.1: + lavc/flacdsp: do not assume maximum R-V VL + avformat/flacdec: Reorder allocations to avoid leak on error + avcodec/adts_parser: Don't presume buffer to be padded + avformat/movenc: Check av_malloc() + avcodec/vp8: Return error on error + avformat/mov: store sample_sizes as unsigned ints + avformat/vvc: fix parsing sps_subpic_id + avformat/vvc: initialize some ptl flags + avcodec/mscc & mwsc: Check loop counts before use + avcodec/mpegvideo_enc: Fix potential overflow in RD + avcodec/mpeg4videodec: assert impossible wrap points + avcodec/mpeg12dec: Use 64bit in bit computation + avcodec/vqcdec: Check init_get_bits8() for failure + avcodec/vvc/dec: Check init_get_bits8() for failure + avcodec/vble: Check av_image_get_buffer_size() for failure + avcodec/vp3: Replace check by assert + avcodec/vp8: Forward return of ff_vpx_init_range_decoder() + avcodec/jpeg2000dec: remove ST=3 case + avcodec/qsvdec: Check av_image_get_buffer_size() for failure + avcodec/exr: Fix preview overflow + avcodec/decode: decode_simple_internal() only implements audio and video + avcodec/fmvc: remove dead assignment + avcodec/h2645_sei: Remove dead checks + avcodec/h264_slice: Remove dead sps check + avcodec/lpc: copy levenson coeffs only when they have been computed + avutil/tests/base64: Check with too short output array + libavutil/base64: Try not to write over the array end + avcodec/cbs_av1: Avoid shift overflow + fftools/ffplay: Check return of swr_alloc_set_opts2() + tools/opt_common: Check for malloc failure + doc/examples/demux_decode: Simplify loop + avformat/concatdec: Check file + avcodec/mpegvideo_enc: Fix 1 line and one column images + avcodec/amrwbdec: assert mode to be valid in decode_fixed_vector() + avcodec/wavarc: fix integer overflow in decode_5elp() block type 2 + swscale/output: Fix integer overflow in yuv2rgba64_full_1_c_template() + swscale/output: Fix integer overflow in yuv2rgba64_1_c_template + avcodec/av1dec: Change bit_depth to int + avcodec/av1dec: bit_depth cannot be another values than 8,10,12 + avcodec/avs3_parser: assert the return value of init_get_bits() + avcodec/avs2_parser: Assert init_get_bits8() success with const size 15 + avfilter/avfiltergraph: return value of ff_request_frame() is unused + avformat/mxfdec: Check body_offset + avformat/kvag: Check sample_rate + avcodec/atrac9dec: Check init_get_bits8() for failure + avcodec/ac3_parser: Check init_get_bits8() for failure + avcodec/pngdec: Check last AVFrame before deref + avcodec/hevcdec: Check ref frame + doc/examples/qsv_transcode: Initialize pointer before free + doc/examples/qsv_transcode: Simplify str_to_dict() loop + doc/examples/vaapi_transcode: Simplify loop + doc/examples/qsv_transcode: Simplify loop + avcodec/cbs_h2645: Check NAL space + avfilter/vf_thumbnail_cuda: Set ret before checking it + avfilter/signature_lookup: Dont copy uninitialized stuff around + avfilter/signature_lookup: Fix 2 differences to the refernce SW + avcodec/x86/vp3dsp_init: Set correct function pointer, fix crash + avformat/mp3dec: change bogus error message if read_header encounters EOF + avformat/mp3dec: simplify inner frame size check in mp3_read_header + avformat/mp3dec: only call ffio_ensure_seekback once + avcodec/cbs_h266: read vps_ptl_max_tid before using it + avcodec/cbs_h266: fix sh_collocated_from_l0_flag and sh_collocated_ref_idx infer + avformat/vvc: fix parsing some early VPS bitstream values + avformat/vvc: fix writing general_constraint_info bytes + avutil/ppc/cpu: Also use the machdep.altivec sysctl on NetBSD + lavd/v4l2: Use proper field type for second parameter of ioctl() with BSD's + vulkan_av1: Fix force_integer_mv value + vaapi_av1: Fix force_integer_mv value + av1dec: Add force_integer_mv derived field for decoder use + avutil/iamf: fix offsets for mix_gain options + avformat/iamfdec: check nb_streams in header read + avformat/mov: free the infe allocated item data on failure + avformat/iamf_writer: reject duplicated stream ids in a stream group + avformat/mov: don't read key_size bytes twice in the keys atom + avformat/mov: take into account the first eight bytes in the keys atom + avformat/mov: fix the check for the heif item parsing loop + avutil/iamf: fix mix_gain_class name + av1dec: Fix RefFrameSignBias calculation + avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context() + avcodec/mediacodecenc: Fix return empty packet when bsf is used + avcodec/hevcdec: Fix precedence, bogus film grain warning + avcodec/hevcdec: fix segfault on invalid film grain metadata + lavc/vvc: Skip enhancement layer NAL units + avformat/mov: ignore old infe box versions + vulkan_av1: add workaround for NVIDIA drivers tested on broken CTS + lavc/vulkan_av1: Use av1dec reference order hint information + lavc/av1: Record reference ordering information for each frame + doc/encoders: add missing libxvid option + doc/encoders: remove non-existent flag + fate/ffmpeg: Avoid dependency on samples + avcodec/wavpack: Remove always-false check + avcodec/wavpack: Fix leak and segfault on reallocation error + avcodec/lossless_videoencdsp: Don't presume alignment in diff_bytes + avcodec/ppc/h264dsp: Fix left shifts of negative numbers + version 7.0: - DXV DXT1 encoder - LEAD MCMP decoder @@ -17,7 +523,7 @@ version 7.0: - qrencode filter and qrencodesrc source - quirc filter - lavu/eval: introduce randomi() function in expressions -- VVC decoder +- VVC decoder (experimental) - fsync filter - Raw Captions with Time (RCWT) closed caption muxer - ffmpeg CLI -bsf option may now be used for input as well as output @@ -38,6 +544,15 @@ version 7.0: - ffplay with hwaccel decoding support (depends on vulkan renderer via libplacebo) - dnn filter libtorch backend - Android content URIs protocol +- AOMedia Film Grain Synthesis 1 (AFGS1) +- RISC-V optimizations for AAC, FLAC, JPEG-2000, LPC, RV4.0, SVQ, VC1, VP8, and more +- Loongarch optimizations for HEVC decoding +- Important AArch64 optimizations for HEVC +- IAMF support inside MP4/ISOBMFF +- Support for HEIF/AVIF still images and tiled still images +- Dolby Vision profile 10 support in AV1 +- Support for Ambient Viewing Environment metadata in MP4/ISOBMFF +- HDR10 metadata passthrough when encoding with libx264, libx265, and libsvtav1 version 6.1: diff --git a/INSTALL.md b/INSTALL.md index 3b220bc6ff..bdf5814014 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -15,3 +15,11 @@ NOTICE ------ - Non system dependencies (e.g. libx264, libvpx) are disabled by default. + +NOTICE for Package Maintainers +------------------------------ + + - It is recommended to build FFmpeg twice, first with minimal external dependencies so + that 3rd party packages, which depend on FFmpegs libavutil/libavfilter/libavcodec/libavformat + can then be built. And last build FFmpeg with full dependancies (which may in turn depend on + some of these 3rd party packages). This avoids circular dependencies during build. diff --git a/MAINTAINERS b/MAINTAINERS index dd633f37e8..a1599c7b0c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -34,8 +34,8 @@ Miscellaneous Areas =================== documentation Stefano Sabatini, Mike Melanson, Timothy Gu, Gyan Doshi -project server day to day operations Árpád Gereöffy, Michael Niedermayer, Reimar Doeffinger, Alexander Strasser, Nikolay Aleksandrov -project server emergencies Árpád Gereöffy, Reimar Doeffinger, Alexander Strasser, Nikolay Aleksandrov +project server day to day operations Árpád Gereöffy, Michael Niedermayer, Reimar Doeffinger, Alexander Strasser, Nikolay Aleksandrov, Timo Rothenpieler +project server emergencies Árpád Gereöffy, Reimar Doeffinger, Alexander Strasser, Nikolay Aleksandrov, Timo Rothenpieler presets Robert Swain metadata subsystem Aurelien Jacobs release management Michael Niedermayer @@ -535,10 +535,12 @@ wm4 Releases ======== +7.0 Michael Niedermayer +6.1 Michael Niedermayer +5.1 Michael Niedermayer +4.4 Michael Niedermayer +3.4 Michael Niedermayer 2.8 Michael Niedermayer -2.7 Michael Niedermayer -2.6 Michael Niedermayer -2.5 Michael Niedermayer If you want to maintain an older release, please contact us diff --git a/RELEASE b/RELEASE index 238679db50..a50da181e9 100644 --- a/RELEASE +++ b/RELEASE @@ -1 +1 @@ -5.1.git +7.0.3 diff --git a/RELEASE_NOTES b/RELEASE_NOTES new file mode 100644 index 0000000000..93bcf7d5bd --- /dev/null +++ b/RELEASE_NOTES @@ -0,0 +1,15 @@ + + ┌─────────────────────────────────────────┐ + │ RELEASE NOTES for FFmpeg 7.0 "Dijkstra" │ + └─────────────────────────────────────────┘ + + The FFmpeg Project proudly presents FFmpeg 7.0 "Dijkstra", about 6 + months after the release of FFmpeg 6.1. + + A complete Changelog is available at the root of the project, and the + complete Git history on https://git.ffmpeg.org/gitweb/ffmpeg.git + + We hope you will like this release as much as we enjoyed working on it, and + as usual, if you have any questions about it, or any FFmpeg related topic, + feel free to join us on the #ffmpeg IRC channel (on irc.libera.chat) or ask + on the mailing-lists. diff --git a/configure b/configure index 2a1d22310b..1aca2f7864 100755 --- a/configure +++ b/configure @@ -2212,6 +2212,7 @@ ARCH_EXT_LIST_PPC=" ldbrx power8 ppc4xx + vec_xl vsx " @@ -2517,6 +2518,7 @@ HAVE_LIST=" opencl_videotoolbox perl pod2man + posix_ioctl texi2html xmllint zlib_gzip @@ -2748,6 +2750,7 @@ altivec_deps="ppc" dcbzl_deps="ppc" ldbrx_deps="ppc" ppc4xx_deps="ppc" +vec_xl_deps="altivec" vsx_deps="altivec" power8_deps="vsx" @@ -2851,6 +2854,7 @@ h264_sei_select="atsc_a53 golomb" hevcparse_select="golomb" hevc_sei_select="atsc_a53 golomb" frame_thread_encoder_deps="encoders threads" +iamfdec_select="iso_media mpeg4audio" inflate_wrapper_deps="zlib" intrax8_select="blockdsp wmv2dsp" iso_media_select="mpeg4audio" @@ -2894,7 +2898,7 @@ asv1_encoder_select="aandcttables bswapdsp fdctdsp pixblockdsp" asv2_decoder_select="blockdsp bswapdsp idctdsp" asv2_encoder_select="aandcttables bswapdsp fdctdsp pixblockdsp" atrac1_decoder_select="sinewin" -av1_decoder_select="cbs_av1 atsc_a53" +av1_decoder_select="atsc_a53 cbs_av1 dovi_rpu" bink_decoder_select="blockdsp hpeldsp" binkaudio_dct_decoder_select="wma_freqs" binkaudio_rdft_decoder_select="wma_freqs" @@ -3483,7 +3487,7 @@ libcelt_decoder_deps="libcelt" libcodec2_decoder_deps="libcodec2" libcodec2_encoder_deps="libcodec2" libdav1d_decoder_deps="libdav1d" -libdav1d_decoder_select="atsc_a53" +libdav1d_decoder_select="atsc_a53 dovi_rpu" libdavs2_decoder_deps="libdavs2" libdavs2_decoder_select="avs2_parser" libfdk_aac_decoder_deps="libfdk_aac" @@ -4061,6 +4065,8 @@ if test "$target_os_default" = aix; then arch_default=$(uname -p) strip_default="strip -X32_64" nm_default="nm -g -X32_64" +elif test "$MSYSTEM_CARCH" != ""; then + arch_default="$MSYSTEM_CARCH" else arch_default=$(uname -m) fi @@ -5761,6 +5767,13 @@ case $target_os in clang_version=$($cc -dumpversion) test ${clang_version%%.*} -eq 11 && add_cflags -fno-stack-check fi + + # Xcode Clang doesn't default to -fno-common while upstream llvm.org + # Clang (and GCC) do. This avoids linker warnings on Xcode 16.3 about + # "reducing alignment of section __DATA,__common from 0x8000 to 0x4000 + # because it exceeds segment maximum alignment". + check_cflags -fno-common + ;; msys*) die "Native MSYS builds are discouraged, please use the MINGW environment." @@ -6351,6 +6364,11 @@ elif enabled ppc; then check_cpp_condition power8 "altivec.h" "defined(_ARCH_PWR8)" fi + if enabled altivec; then + check_cc vec_xl altivec.h "const unsigned char *y1i = { 0 }; + vector unsigned char y0 = vec_xl(0, y1i);" + fi + elif enabled riscv; then enabled rv && check_inline_asm rv '".option arch, +zbb\nrev8 t0, t1"' @@ -6439,6 +6457,9 @@ check_cc intrinsics_neon arm_neon.h "int16x8_t test = vdupq_n_s16(0)" check_ldflags -Wl,--as-needed check_ldflags -Wl,-z,noexecstack +if [ $target_os = "darwin" ]; then + check_ldflags -Wl,-no_warn_duplicate_libraries +fi if ! disabled network; then check_func getaddrinfo $network_extralibs @@ -7128,14 +7149,16 @@ enabled makeinfo \ disabled makeinfo_html && texi2html --help 2> /dev/null | grep -q 'init-file' && enable texi2html || disable texi2html perl -v > /dev/null 2>&1 && enable perl || disable perl pod2man --help > /dev/null 2>&1 && enable pod2man || disable pod2man -rsync --help 2> /dev/null | grep -q 'contimeout' && enable rsync_contimeout || disable rsync_contimeout +rsync --help 2> /dev/null | grep -q 'contimeout=' && enable rsync_contimeout || disable rsync_contimeout xmllint --version > /dev/null 2>&1 && enable xmllint || disable xmllint +check_headers linux/fb.h +check_headers linux/videodev2.h +test_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_sanitized struct_v4l2_frmivalenum_discrete +test_code cc sys/ioctl.h "int ioctl(int, int, ...)" && enable posix_ioctl + # check V4L2 codecs available in the API if enabled v4l2_m2m; then - check_headers linux/fb.h - check_headers linux/videodev2.h - test_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_sanitized struct_v4l2_frmivalenum_discrete check_cc v4l2_m2m linux/videodev2.h "int i = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_VIDEO_M2M | V4L2_BUF_FLAG_LAST;" check_cc vc1_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VC1_ANNEX_G;" check_cc mpeg1_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_MPEG1;" @@ -7310,7 +7333,7 @@ fi if enabled x86; then case $target_os in - mingw32*|mingw64*|win32|win64|linux|cygwin*) + freebsd|mingw32*|mingw64*|win32|win64|linux|cygwin*) ;; *) disable ffnvcodec cuvid nvdec nvenc @@ -7895,6 +7918,7 @@ if enabled ppc; then echo "POWER8 enabled ${power8-no}" echo "PPC 4xx optimizations ${ppc4xx-no}" echo "dcbzl available ${dcbzl-no}" + echo "vec_xl available ${vec_xl-no}" fi if enabled loongarch; then echo "LSX enabled ${lsx-no}" diff --git a/doc/Doxyfile b/doc/Doxyfile index 572c532da5..c3d1ed38c0 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = FFmpeg # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = +PROJECT_NUMBER = 7.0.3 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/doc/demuxers.texi b/doc/demuxers.texi index b70f3a38d7..29d1b0a8a8 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -567,6 +567,13 @@ prefer to use #EXT-X-START if it's in playlist instead of live_start_index. @item allowed_extensions ',' separated list of file extensions that hls is allowed to access. +@item extension_picky +This blocks disallowed extensions from probing +It also requires all available segments to have matching extensions to the format +except mpegts, which is always allowed. +It is recommended to set the whitelists correctly instead of depending on extensions +Enabled by default. + @item max_reload Maximum number of times a insufficient list is attempted to be reloaded. Default value is 1000. diff --git a/doc/developer.texi b/doc/developer.texi index c86bb5820c..1d78647f8b 100644 --- a/doc/developer.texi +++ b/doc/developer.texi @@ -390,6 +390,10 @@ If you apply a patch, send an answer to ffmpeg-devel (or wherever you got the patch from) saying that you applied the patch. +@subheading Credit any researchers +If a commit/patch fixes an issues found by some researcher, always credit the +researcher in the commit message for finding/reporting the issue. + @subheading Always wait long enough before pushing changes Do NOT commit to code actively maintained by others without permission. Send a patch to ffmpeg-devel. If no one answers within a reasonable @@ -634,6 +638,11 @@ patch is inline or attached per mail. You can check @url{https://patchwork.ffmpeg.org}, if your patch does not show up, its mime type likely was wrong. +@subheading How to setup git send-email? + +Please see @url{https://git-send-email.io/}. +For gmail additionally see @url{https://shallowsky.com/blog/tech/email/gmail-app-passwds.html}. + @subheading Sending patches from email clients Using @code{git send-email} might not be desirable for everyone. The following trick allows to send patches via email clients in a safe @@ -918,6 +927,25 @@ In case you need finer control over how valgrind is invoked, use the @code{--target-exec='valgrind } option in your configure line instead. +@anchor{Maintenance} +@chapter Maintenance process + +@anchor{MAINTAINERS} +@section MAINTAINERS + +The developers maintaining each part of the codebase are listed in @file{MAINTAINERS}. +Being listed in @file{MAINTAINERS}, gives one the right to have git write access to +the specific repository. + +@anchor{Becoming a maintainer} +@section Becoming a maintainer + +People add themselves to @file{MAINTAINERS} by sending a patch like any other code +change. These get reviewed by the community like any other patch. It is expected +that, if someone has an objection to a new maintainer, she is willing to object +in public with her full name and is willing to take over maintainership for the area. + + @anchor{Release process} @chapter Release process diff --git a/doc/encoders.texi b/doc/encoders.texi index 7c223ed74c..840382a25a 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3045,9 +3045,6 @@ Enable high quality AC prediction. @item gray Only encode grayscale. -@item gmc -Enable the use of global motion compensation (GMC). - @item qpel Enable quarter-pixel motion compensation. @@ -3059,7 +3056,9 @@ Place global headers in extradata instead of every keyframe. @end table -@item trellis +@item gmc +Enable the use of global motion compensation (GMC). Default is 0 +(disabled). @item me_quality Set motion estimation quality level. Possible values in decreasing order of @@ -3114,6 +3113,9 @@ be better than any of the two specified individually. In other words, the resulting quality will be the worse one of the two effects. +@item trellis +Set rate-distortion optimal quantization. + @item ssim Set structural similarity (SSIM) displaying method. Possible values: diff --git a/doc/examples/demux_decode.c b/doc/examples/demux_decode.c index f26611d8f4..64f5547bc4 100644 --- a/doc/examples/demux_decode.c +++ b/doc/examples/demux_decode.c @@ -138,11 +138,9 @@ static int decode_packet(AVCodecContext *dec, const AVPacket *pkt) ret = output_audio_frame(frame); av_frame_unref(frame); - if (ret < 0) - return ret; } - return 0; + return ret; } static int open_codec_context(int *stream_idx, diff --git a/doc/examples/mux.c b/doc/examples/mux.c index b034aad56f..0f3a2bb125 100644 --- a/doc/examples/mux.c +++ b/doc/examples/mux.c @@ -347,8 +347,7 @@ static int write_audio_frame(AVFormatContext *oc, OutputStream *ost) if (frame) { /* convert samples from native format to destination codec format, using the resampler */ /* compute destination number of samples */ - dst_nb_samples = av_rescale_rnd(swr_get_delay(ost->swr_ctx, c->sample_rate) + frame->nb_samples, - c->sample_rate, c->sample_rate, AV_ROUND_UP); + dst_nb_samples = swr_get_delay(ost->swr_ctx, c->sample_rate) + frame->nb_samples; av_assert0(dst_nb_samples == frame->nb_samples); /* when we pass a frame to the encoder, it may keep a reference to it diff --git a/doc/examples/qsv_transcode.c b/doc/examples/qsv_transcode.c index 972126800b..ff115f3669 100644 --- a/doc/examples/qsv_transcode.c +++ b/doc/examples/qsv_transcode.c @@ -75,8 +75,7 @@ static int str_to_dict(char* optstr, AVDictionary **opt) if (value == NULL) return AVERROR(EINVAL); av_dict_set(opt, key, value, 0); - } while(key != NULL); - return 0; + } while(1); } static int dynamic_set_parameter(AVCodecContext *avctx) @@ -334,17 +333,15 @@ static int dec_enc(AVPacket *pkt, const AVCodec *enc_codec, char *optstr) fail: av_frame_free(&frame); - if (ret < 0) - return ret; } - return 0; + return ret; } int main(int argc, char **argv) { const AVCodec *enc_codec; int ret = 0; - AVPacket *dec_pkt; + AVPacket *dec_pkt = NULL; if (argc < 5 || (argc - 5) % 2) { av_log(NULL, AV_LOG_ERROR, "Usage: %s " diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c index d5f472f6dd..ff3ebb1e2b 100644 --- a/doc/examples/vaapi_encode.c +++ b/doc/examples/vaapi_encode.c @@ -88,6 +88,10 @@ static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout) enc_pkt->stream_index = 0; ret = fwrite(enc_pkt->data, enc_pkt->size, 1, fout); av_packet_unref(enc_pkt); + if (ret != enc_pkt->size) { + ret = AVERROR(errno); + break; + } } end: diff --git a/doc/examples/vaapi_transcode.c b/doc/examples/vaapi_transcode.c index 8367cb3040..e1b7a43883 100644 --- a/doc/examples/vaapi_transcode.c +++ b/doc/examples/vaapi_transcode.c @@ -215,10 +215,8 @@ static int dec_enc(AVPacket *pkt, const AVCodec *enc_codec) fail: av_frame_free(&frame); - if (ret < 0) - return ret; } - return 0; + return ret; } int main(int argc, char **argv) diff --git a/doc/infra.txt b/doc/infra.txt index 30a85dd5ce..79d4e56719 100644 --- a/doc/infra.txt +++ b/doc/infra.txt @@ -23,6 +23,8 @@ Web, mail, and public facing git, also website git fftrac VM: ---------- trac.ffmpeg.org Issue tracking +gpg encrypted backups of the trac repositories are created once a day +and can be downloaded by any of the admins. ffaux VM: @@ -65,6 +67,9 @@ Github mirrors are redundantly synced by multiple people You need a new git repository related to FFmpeg ? contact root at ffmpeg.org +git repositories are managed by gitolite, every change to permissions is +logged, including when, what and by whom + Fate: ~~~~~ diff --git a/doc/t2h.pm b/doc/t2h.pm index b7485e1f1e..4875d66305 100644 --- a/doc/t2h.pm +++ b/doc/t2h.pm @@ -54,12 +54,24 @@ sub get_formatting_function($$) { } # determine texinfo version -my $program_version_num = version->declare(ff_get_conf('PACKAGE_VERSION'))->numify; +my $package_version = ff_get_conf('PACKAGE_VERSION'); +$package_version =~ s/\+dev$//; +my $program_version_num = version->declare($package_version)->numify; my $program_version_6_8 = $program_version_num >= 6.008000; # no navigation elements ff_set_from_init_file('HEADERS', 0); +my %sectioning_commands = %Texinfo::Common::sectioning_commands; +if (scalar(keys(%sectioning_commands)) == 0) { + %sectioning_commands = %Texinfo::Commands::sectioning_heading_commands; +} + +my %root_commands = %Texinfo::Common::root_commands; +if (scalar(keys(%root_commands)) == 0) { + %root_commands = %Texinfo::Commands::root_commands; +} + sub ffmpeg_heading_command($$$$$) { my $self = shift; @@ -77,6 +89,9 @@ sub ffmpeg_heading_command($$$$$) return $result; } + # no need to set it as the $element_id is output unconditionally + my $heading_id; + my $element_id = $self->command_id($command); $result .= "\n" if (defined($element_id) and $element_id ne ''); @@ -84,24 +99,40 @@ sub ffmpeg_heading_command($$$$$) print STDERR "Process $command " .Texinfo::Structuring::_print_root_command_texi($command)."\n" if ($self->get_conf('DEBUG')); - my $element; - if ($Texinfo::Common::root_commands{$command->{'cmdname'}} - and $command->{'parent'} - and $command->{'parent'}->{'type'} - and $command->{'parent'}->{'type'} eq 'element') { - $element = $command->{'parent'}; + my $output_unit; + if ($root_commands{$command->{'cmdname'}}) { + if ($command->{'associated_unit'}) { + $output_unit = $command->{'associated_unit'}; + } elsif ($command->{'structure'} + and $command->{'structure'}->{'associated_unit'}) { + $output_unit = $command->{'structure'}->{'associated_unit'}; + } elsif ($command->{'parent'} + and $command->{'parent'}->{'type'} + and $command->{'parent'}->{'type'} eq 'element') { + $output_unit = $command->{'parent'}; + } } - if ($element) { + + if ($output_unit) { $result .= &{get_formatting_function($self, 'format_element_header')}($self, $cmdname, - $command, $element); + $command, $output_unit); } my $heading_level; # node is used as heading if there is nothing else. if ($cmdname eq 'node') { - if (!$element or (!$element->{'extra'}->{'section'} - and $element->{'extra'}->{'node'} - and $element->{'extra'}->{'node'} eq $command + if (!$output_unit or + (((!$output_unit->{'extra'}->{'section'} + and $output_unit->{'extra'}->{'node'} + and $output_unit->{'extra'}->{'node'} eq $command) + or + ((($output_unit->{'extra'}->{'unit_command'} + and $output_unit->{'extra'}->{'unit_command'} eq $command) + or + ($output_unit->{'unit_command'} + and $output_unit->{'unit_command'} eq $command)) + and $command->{'extra'} + and not $command->{'extra'}->{'associated_section'})) # bogus node may not have been normalized and defined($command->{'extra'}->{'normalized'}))) { if ($command->{'extra'}->{'normalized'} eq 'Top') { @@ -111,7 +142,15 @@ sub ffmpeg_heading_command($$$$$) } } } else { - $heading_level = $command->{'level'}; + if (defined($command->{'extra'}) + and defined($command->{'extra'}->{'section_level'})) { + $heading_level = $command->{'extra'}->{'section_level'}; + } elsif ($command->{'structure'} + and defined($command->{'structure'}->{'section_level'})) { + $heading_level = $command->{'structure'}->{'section_level'}; + } else { + $heading_level = $command->{'level'}; + } } my $heading = $self->command_text($command); @@ -119,8 +158,8 @@ sub ffmpeg_heading_command($$$$$) # if there is an error in the node. if (defined($heading) and $heading ne '' and defined($heading_level)) { - if ($Texinfo::Common::root_commands{$cmdname} - and $Texinfo::Common::sectioning_commands{$cmdname}) { + if ($root_commands{$cmdname} + and $sectioning_commands{$cmdname}) { my $content_href = $self->command_contents_href($command, 'contents', $self->{'current_filename'}); if ($content_href) { @@ -140,7 +179,13 @@ sub ffmpeg_heading_command($$$$$) } } - if ($self->in_preformatted()) { + my $in_preformatted; + if ($program_version_num >= 7.001090) { + $in_preformatted = $self->in_preformatted_context(); + } else { + $in_preformatted = $self->in_preformatted(); + } + if ($in_preformatted) { $result .= $heading."\n"; } else { # if the level was changed, set the command name right @@ -149,21 +194,25 @@ sub ffmpeg_heading_command($$$$$) $cmdname = $Texinfo::Common::level_to_structuring_command{$cmdname}->[$heading_level]; } - # format_heading_text expects an array of headings for texinfo >= 7.0 if ($program_version_num >= 7.000000) { - $heading = [$heading]; - } - $result .= &{get_formatting_function($self,'format_heading_text')}( + $result .= &{get_formatting_function($self,'format_heading_text')}($self, + $cmdname, [$cmdname], $heading, + $heading_level +$self->get_conf('CHAPTER_HEADER_LEVEL') -1, + $heading_id, $command); + + } else { + $result .= &{get_formatting_function($self,'format_heading_text')}( $self, $cmdname, $heading, $heading_level + $self->get_conf('CHAPTER_HEADER_LEVEL') - 1, $command); + } } } $result .= $content if (defined($content)); return $result; } -foreach my $command (keys(%Texinfo::Common::sectioning_commands), 'node') { +foreach my $command (keys(%sectioning_commands), 'node') { texinfo_register_command_formatting($command, \&ffmpeg_heading_command); } @@ -188,28 +237,56 @@ sub ffmpeg_begin_file($$$) my $filename = shift; my $element = shift; - my $command; - if ($element and $self->get_conf('SPLIT')) { - $command = $self->element_command($element); + my ($element_command, $node_command, $command_for_title); + if ($element) { + if ($element->{'unit_command'}) { + $element_command = $element->{'unit_command'}; + } elsif ($self->can('tree_unit_element_command')) { + $element_command = $self->tree_unit_element_command($element); + } elsif ($self->can('tree_unit_element_command')) { + $element_command = $self->element_command($element); + } + + $node_command = $element_command; + if ($element_command and $element_command->{'cmdname'} + and $element_command->{'cmdname'} ne 'node' + and $element_command->{'extra'} + and $element_command->{'extra'}->{'associated_node'}) { + $node_command = $element_command->{'extra'}->{'associated_node'}; + } + + $command_for_title = $element_command if ($self->get_conf('SPLIT')); } - my ($title, $description, $encoding, $date, $css_lines, - $doctype, $bodytext, $copying_comment, $after_body_open, - $extra_head, $program_and_version, $program_homepage, + my ($title, $description, $keywords, $encoding, $date, $css_lines, $doctype, + $root_html_element_attributes, $body_attributes, $copying_comment, + $after_body_open, $extra_head, $program_and_version, $program_homepage, $program, $generator); - if ($program_version_num >= 7.000000) { - ($title, $description, $encoding, $date, $css_lines, - $doctype, $bodytext, $copying_comment, $after_body_open, + if ($program_version_num >= 7.001090) { + ($title, $description, $keywords, $encoding, $date, $css_lines, $doctype, + $root_html_element_attributes, $body_attributes, $copying_comment, + $after_body_open, $extra_head, $program_and_version, $program_homepage, + $program, $generator) = $self->_file_header_information($command_for_title, + $filename); + } elsif ($program_version_num >= 7.000000) { + ($title, $description, $encoding, $date, $css_lines, $doctype, + $root_html_element_attributes, $copying_comment, $after_body_open, $extra_head, $program_and_version, $program_homepage, - $program, $generator) = $self->_file_header_information($command); + $program, $generator) = $self->_file_header_information($command_for_title, + $filename); } else { ($title, $description, $encoding, $date, $css_lines, - $doctype, $bodytext, $copying_comment, $after_body_open, - $extra_head, $program_and_version, $program_homepage, - $program, $generator) = $self->_file_header_informations($command); + $doctype, $root_html_element_attributes, $copying_comment, + $after_body_open, $extra_head, $program_and_version, $program_homepage, + $program, $generator) = $self->_file_header_informations($command_for_title); } - my $links = $self->_get_links ($filename, $element); + my $links; + if ($program_version_num >= 7.000000) { + $links = $self->_get_links($filename, $element, $node_command); + } else { + $links = $self->_get_links ($filename, $element); + } my $head1 = $ENV{"FFMPEG_HEADER1"} || < @@ -252,13 +329,25 @@ sub ffmpeg_program_string($) if (defined($self->get_conf('PROGRAM')) and $self->get_conf('PROGRAM') ne '' and defined($self->get_conf('PACKAGE_URL'))) { - return $self->convert_tree( + if ($program_version_num >= 7.001090) { + return $self->convert_tree( + $self->cdt('This document was generated using @uref{{program_homepage}, @emph{{program}}}.', + { 'program_homepage' => {'text' => $self->get_conf('PACKAGE_URL')}, + 'program' => {'text' => $self->get_conf('PROGRAM') }})); + } else { + return $self->convert_tree( $self->gdt('This document was generated using @uref{{program_homepage}, @emph{{program}}}.', - { 'program_homepage' => $self->get_conf('PACKAGE_URL'), - 'program' => $self->get_conf('PROGRAM') })); + { 'program_homepage' => {'text' => $self->get_conf('PACKAGE_URL')}, + 'program' => {'text' => $self->get_conf('PROGRAM') }})); + } } else { - return $self->convert_tree( - $self->gdt('This document was generated automatically.')); + if ($program_version_num >= 7.001090) { + return $self->convert_tree( + $self->cdt('This document was generated automatically.')); + } else { + return $self->convert_tree( + $self->gdt('This document was generated automatically.')); + } } } if ($program_version_6_8) { diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index f3c258bb99..309ec4d32f 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -581,7 +581,7 @@ static const AVOption *opt_find(void *obj, const char *name, const char *unit, return o; } -#define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0 +#define FLAGS ((o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0) int opt_default(void *optctx, const char *opt, const char *arg) { const AVOption *o; diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d4e5f978f1..4a0c7d5c4d 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -306,8 +306,9 @@ static int read_key(void) } //Read it if(nchars != 0) { - read(0, &ch, 1); - return ch; + if (read(0, &ch, 1) == 1) + return ch; + return 0; }else{ return -1; } diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 47312c9fe1..c6b8af8909 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -907,9 +907,18 @@ static int ist_use(InputStream *ist, int decoding_needed) if (decoding_needed && ds->sch_idx_dec < 0) { int is_audio = ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO; + int is_unreliable = !!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS); + int64_t use_wallclock_as_timestamps; + + ret = av_opt_get_int(d->f.ctx, "use_wallclock_as_timestamps", 0, &use_wallclock_as_timestamps); + if (ret < 0) + return ret; + + if (use_wallclock_as_timestamps) + is_unreliable = 0; ds->dec_opts.flags = (!!ist->fix_sub_duration * DECODER_FLAG_FIX_SUB_DURATION) | - (!!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS) * DECODER_FLAG_TS_UNRELIABLE) | + (!!is_unreliable * DECODER_FLAG_TS_UNRELIABLE) | (!!(d->loop && is_audio) * DECODER_FLAG_SEND_END_TS) #if FFMPEG_OPT_TOP | ((ist->top_field_first >= 0) * DECODER_FLAG_TOP_FIELD_FIRST) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 5f7fcf8a5f..447f133137 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -171,7 +171,7 @@ int enc_open(void *opaque, const AVFrame *frame) InputStream *ist = ost->ist; Encoder *e = ost->enc; AVCodecContext *enc_ctx = ost->enc_ctx; - Decoder *dec; + Decoder *dec = NULL; const AVCodec *enc = enc_ctx->codec; OutputFile *of = ost->file; FrameData *fd; @@ -504,9 +504,9 @@ void enc_stats_write(OutputStream *ost, EncStats *es, AVRational tbi = (AVRational){ 0, 1}; int64_t ptsi = INT64_MAX; - const FrameData *fd; + const FrameData *fd = NULL; - if ((frame && frame->opaque_ref) || (pkt && pkt->opaque_ref)) { + if (frame ? frame->opaque_ref : pkt->opaque_ref) { fd = (const FrameData*)(frame ? frame->opaque_ref->data : pkt->opaque_ref->data); tbi = fd->dec.tb; ptsi = fd->dec.pts; diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index ec88017e21..ee3af45908 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -260,6 +260,12 @@ typedef struct SchFilterGraph { int task_exited; } SchFilterGraph; +enum SchedulerState { + SCH_STATE_UNINIT, + SCH_STATE_STARTED, + SCH_STATE_STOPPED, +}; + struct Scheduler { const AVClass *class; @@ -292,7 +298,7 @@ struct Scheduler { char *sdp_filename; int sdp_auto; - int transcode_started; + enum SchedulerState state; atomic_int terminate; atomic_int task_failed; @@ -399,22 +405,6 @@ static int queue_alloc(ThreadQueue **ptq, unsigned nb_streams, unsigned queue_si static void *task_wrapper(void *arg); -static int task_stop(SchTask *task) -{ - int ret; - void *thread_ret; - - if (!task->thread_running) - return 0; - - ret = pthread_join(task->thread, &thread_ret); - av_assert0(ret == 0); - - task->thread_running = 0; - - return (intptr_t)thread_ret; -} - static int task_start(SchTask *task) { int ret; @@ -468,59 +458,6 @@ static int64_t trailing_dts(const Scheduler *sch, int count_finished) return min_dts == INT64_MAX ? AV_NOPTS_VALUE : min_dts; } -int sch_stop(Scheduler *sch, int64_t *finish_ts) -{ - int ret = 0, err; - - atomic_store(&sch->terminate, 1); - - for (unsigned type = 0; type < 2; type++) - for (unsigned i = 0; i < (type ? sch->nb_demux : sch->nb_filters); i++) { - SchWaiter *w = type ? &sch->demux[i].waiter : &sch->filters[i].waiter; - waiter_set(w, 1); - } - - for (unsigned i = 0; i < sch->nb_demux; i++) { - SchDemux *d = &sch->demux[i]; - - err = task_stop(&d->task); - ret = err_merge(ret, err); - } - - for (unsigned i = 0; i < sch->nb_dec; i++) { - SchDec *dec = &sch->dec[i]; - - err = task_stop(&dec->task); - ret = err_merge(ret, err); - } - - for (unsigned i = 0; i < sch->nb_filters; i++) { - SchFilterGraph *fg = &sch->filters[i]; - - err = task_stop(&fg->task); - ret = err_merge(ret, err); - } - - for (unsigned i = 0; i < sch->nb_enc; i++) { - SchEnc *enc = &sch->enc[i]; - - err = task_stop(&enc->task); - ret = err_merge(ret, err); - } - - for (unsigned i = 0; i < sch->nb_mux; i++) { - SchMux *mux = &sch->mux[i]; - - err = task_stop(&mux->task); - ret = err_merge(ret, err); - } - - if (finish_ts) - *finish_ts = trailing_dts(sch, 1); - - return ret; -} - void sch_free(Scheduler **psch) { Scheduler *sch = *psch; @@ -1213,7 +1150,8 @@ int sch_mux_stream_ready(Scheduler *sch, unsigned mux_idx, unsigned stream_idx) // this may be called during initialization - do not start // threads before sch_start() is called - if (++mux->nb_streams_ready == mux->nb_streams && sch->transcode_started) + if (++mux->nb_streams_ready == mux->nb_streams && + sch->state >= SCH_STATE_STARTED) ret = mux_init(sch, mux); pthread_mutex_unlock(&sch->mux_ready_lock); @@ -1583,7 +1521,8 @@ int sch_start(Scheduler *sch) if (ret < 0) return ret; - sch->transcode_started = 1; + av_assert0(sch->state == SCH_STATE_UNINIT); + sch->state = SCH_STATE_STARTED; for (unsigned i = 0; i < sch->nb_mux; i++) { SchMux *mux = &sch->mux[i]; @@ -1591,7 +1530,7 @@ int sch_start(Scheduler *sch) if (mux->nb_streams_ready == mux->nb_streams) { ret = mux_init(sch, mux); if (ret < 0) - return ret; + goto fail; } } @@ -1600,7 +1539,7 @@ int sch_start(Scheduler *sch) ret = task_start(&enc->task); if (ret < 0) - return ret; + goto fail; } for (unsigned i = 0; i < sch->nb_filters; i++) { @@ -1608,7 +1547,7 @@ int sch_start(Scheduler *sch) ret = task_start(&fg->task); if (ret < 0) - return ret; + goto fail; } for (unsigned i = 0; i < sch->nb_dec; i++) { @@ -1616,7 +1555,7 @@ int sch_start(Scheduler *sch) ret = task_start(&dec->task); if (ret < 0) - return ret; + goto fail; } for (unsigned i = 0; i < sch->nb_demux; i++) { @@ -1627,7 +1566,7 @@ int sch_start(Scheduler *sch) ret = task_start(&d->task); if (ret < 0) - return ret; + goto fail; } pthread_mutex_lock(&sch->schedule_lock); @@ -1635,6 +1574,9 @@ int sch_start(Scheduler *sch) pthread_mutex_unlock(&sch->schedule_lock); return 0; +fail: + sch_stop(sch, NULL); + return ret; } int sch_wait(Scheduler *sch, uint64_t timeout_us, int64_t *transcode_ts) @@ -2483,6 +2425,18 @@ int sch_filter_command(Scheduler *sch, unsigned fg_idx, AVFrame *frame) return send_to_filter(sch, fg, fg->nb_inputs, frame); } +static int task_cleanup(Scheduler *sch, SchedulerNode node) +{ + switch (node.type) { + case SCH_NODE_TYPE_DEMUX: return demux_done (sch, node.idx); + case SCH_NODE_TYPE_MUX: return mux_done (sch, node.idx); + case SCH_NODE_TYPE_DEC: return dec_done (sch, node.idx); + case SCH_NODE_TYPE_ENC: return enc_done (sch, node.idx); + case SCH_NODE_TYPE_FILTER_IN: return filter_done(sch, node.idx); + default: av_assert0(0); + } +} + static void *task_wrapper(void *arg) { SchTask *task = arg; @@ -2495,15 +2449,7 @@ static void *task_wrapper(void *arg) av_log(task->func_arg, AV_LOG_ERROR, "Task finished with error code: %d (%s)\n", ret, av_err2str(ret)); - switch (task->node.type) { - case SCH_NODE_TYPE_DEMUX: err = demux_done (sch, task->node.idx); break; - case SCH_NODE_TYPE_MUX: err = mux_done (sch, task->node.idx); break; - case SCH_NODE_TYPE_DEC: err = dec_done (sch, task->node.idx); break; - case SCH_NODE_TYPE_ENC: err = enc_done (sch, task->node.idx); break; - case SCH_NODE_TYPE_FILTER_IN: err = filter_done(sch, task->node.idx); break; - default: av_assert0(0); - } - + err = task_cleanup(sch, task->node); ret = err_merge(ret, err); // EOF is considered normal termination @@ -2518,3 +2464,77 @@ static void *task_wrapper(void *arg) return (void*)(intptr_t)ret; } + +static int task_stop(Scheduler *sch, SchTask *task) +{ + int ret; + void *thread_ret; + + if (!task->thread_running) + return task_cleanup(sch, task->node); + + ret = pthread_join(task->thread, &thread_ret); + av_assert0(ret == 0); + + task->thread_running = 0; + + return (intptr_t)thread_ret; +} + +int sch_stop(Scheduler *sch, int64_t *finish_ts) +{ + int ret = 0, err; + + if (sch->state != SCH_STATE_STARTED) + return 0; + + atomic_store(&sch->terminate, 1); + + for (unsigned type = 0; type < 2; type++) + for (unsigned i = 0; i < (type ? sch->nb_demux : sch->nb_filters); i++) { + SchWaiter *w = type ? &sch->demux[i].waiter : &sch->filters[i].waiter; + waiter_set(w, 1); + } + + for (unsigned i = 0; i < sch->nb_demux; i++) { + SchDemux *d = &sch->demux[i]; + + err = task_stop(sch, &d->task); + ret = err_merge(ret, err); + } + + for (unsigned i = 0; i < sch->nb_dec; i++) { + SchDec *dec = &sch->dec[i]; + + err = task_stop(sch, &dec->task); + ret = err_merge(ret, err); + } + + for (unsigned i = 0; i < sch->nb_filters; i++) { + SchFilterGraph *fg = &sch->filters[i]; + + err = task_stop(sch, &fg->task); + ret = err_merge(ret, err); + } + + for (unsigned i = 0; i < sch->nb_enc; i++) { + SchEnc *enc = &sch->enc[i]; + + err = task_stop(sch, &enc->task); + ret = err_merge(ret, err); + } + + for (unsigned i = 0; i < sch->nb_mux; i++) { + SchMux *mux = &sch->mux[i]; + + err = task_stop(sch, &mux->task); + ret = err_merge(ret, err); + } + + if (finish_ts) + *finish_ts = trailing_dts(sch, 1); + + sch->state = SCH_STATE_STOPPED; + + return ret; +} diff --git a/fftools/ffplay.c b/fftools/ffplay.c index fcd1319ce7..3e1be8038c 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -2394,12 +2394,13 @@ static int audio_decode_frame(VideoState *is) av_channel_layout_compare(&af->frame->ch_layout, &is->audio_src.ch_layout) || af->frame->sample_rate != is->audio_src.freq || (wanted_nb_samples != af->frame->nb_samples && !is->swr_ctx)) { + int ret; swr_free(&is->swr_ctx); - swr_alloc_set_opts2(&is->swr_ctx, + ret = swr_alloc_set_opts2(&is->swr_ctx, &is->audio_tgt.ch_layout, is->audio_tgt.fmt, is->audio_tgt.freq, &af->frame->ch_layout, af->frame->format, af->frame->sample_rate, 0, NULL); - if (!is->swr_ctx || swr_init(is->swr_ctx) < 0) { + if (ret < 0 || swr_init(is->swr_ctx) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n", af->frame->sample_rate, av_get_sample_fmt_name(af->frame->format), af->frame->ch_layout.nb_channels, @@ -2604,6 +2605,11 @@ static int create_hwaccel(AVBufferRef **device_ctx) if (type == AV_HWDEVICE_TYPE_NONE) return AVERROR(ENOTSUP); + if (!vk_renderer) { + av_log(NULL, AV_LOG_ERROR, "Vulkan renderer is not available\n"); + return AVERROR(ENOTSUP); + } + ret = vk_renderer_get_hw_dev(vk_renderer, &vk_dev); if (ret < 0) return ret; @@ -3842,8 +3848,13 @@ int main(int argc, char **argv) if (vk_renderer) { AVDictionary *dict = NULL; - if (vulkan_params) - av_dict_parse_string(&dict, vulkan_params, "=", ":", 0); + if (vulkan_params) { + int ret = av_dict_parse_string(&dict, vulkan_params, "=", ":", 0); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "Failed to parse, %s\n", vulkan_params); + do_exit(NULL); + } + } ret = vk_renderer_create(vk_renderer, window, dict); av_dict_free(&dict); if (ret < 0) { diff --git a/fftools/ffplay_renderer.c b/fftools/ffplay_renderer.c index 73072a2851..fbb68b2376 100644 --- a/fftools/ffplay_renderer.c +++ b/fftools/ffplay_renderer.c @@ -765,7 +765,7 @@ static void destroy(VkRenderer *renderer) vkDestroySurfaceKHR = (PFN_vkDestroySurfaceKHR) ctx->get_proc_addr(ctx->inst, "vkDestroySurfaceKHR"); vkDestroySurfaceKHR(ctx->inst, ctx->vk_surface, NULL); - ctx->vk_surface = NULL; + ctx->vk_surface = VK_NULL_HANDLE; } av_buffer_unref(&ctx->hw_device_ref); diff --git a/fftools/opt_common.c b/fftools/opt_common.c index 947a226d8d..9d2d5184a0 100644 --- a/fftools/opt_common.c +++ b/fftools/opt_common.c @@ -724,10 +724,13 @@ int show_codecs(void *optctx, const char *opt, const char *arg) return 0; } -static void print_codecs(int encoder) +static int print_codecs(int encoder) { const AVCodecDescriptor **codecs; - unsigned i, nb_codecs = get_codecs_sorted(&codecs); + int i, nb_codecs = get_codecs_sorted(&codecs); + + if (nb_codecs < 0) + return nb_codecs; printf("%s:\n" " V..... = Video\n" @@ -762,18 +765,17 @@ static void print_codecs(int encoder) } } av_free(codecs); + return 0; } int show_decoders(void *optctx, const char *opt, const char *arg) { - print_codecs(0); - return 0; + return print_codecs(0); } int show_encoders(void *optctx, const char *opt, const char *arg) { - print_codecs(1); - return 0; + return print_codecs(1); } int show_bsfs(void *optctx, const char *opt, const char *arg) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 9ce6d445c1..113adb22d5 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1068,6 +1068,7 @@ STLIBOBJS-$(CONFIG_ISO_MEDIA) += mpegaudiotabs.o STLIBOBJS-$(CONFIG_FLV_MUXER) += mpeg4audio_sample_rates.o STLIBOBJS-$(CONFIG_HLS_DEMUXER) += ac3_channel_layout_tab.o STLIBOBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER) += jpegxl_parse.o +STLIBOBJS-$(CONFIG_JNI) += ffjni.o STLIBOBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER) += jpegxl_parse.o STLIBOBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio_sample_rates.o STLIBOBJS-$(CONFIG_MOV_DEMUXER) += ac3_channel_layout_tab.o diff --git a/libavcodec/aacps_tablegen_template.c b/libavcodec/aacps_tablegen_template.c index e70edf884b..e05887b9b1 100644 --- a/libavcodec/aacps_tablegen_template.c +++ b/libavcodec/aacps_tablegen_template.c @@ -22,6 +22,8 @@ #include #define BUILD_TABLES +#include "config.h" +#undef CONFIG_HARDCODED_TABLES #define CONFIG_HARDCODED_TABLES 0 #include "aac_defines.h" diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c index cdfaed636b..406d5b2202 100644 --- a/libavcodec/aacsbr_template.c +++ b/libavcodec/aacsbr_template.c @@ -582,6 +582,7 @@ static int sbr_make_f_derived(AACDecContext *ac, SpectralBandReplication *sbr) if (sbr->n_q > 5) { av_log(ac->avctx, AV_LOG_ERROR, "Too many noise floor scale factors: %d\n", sbr->n_q); + sbr->n_q = 1; return -1; } diff --git a/libavcodec/aarch64/h264pred_neon.S b/libavcodec/aarch64/h264pred_neon.S index ea37689f34..d0999938ef 100644 --- a/libavcodec/aarch64/h264pred_neon.S +++ b/libavcodec/aarch64/h264pred_neon.S @@ -502,28 +502,27 @@ function ff_pred16x16_plane_neon_10, export=1 add v7.4h, v7.4h, v0.4h shl v2.4h, v7.4h, #4 ssubl v2.4s, v2.4h, v3.4h - shl v3.4h, v4.4h, #4 ext v0.16b, v0.16b, v0.16b, #14 - ssubl v6.4s, v5.4h, v3.4h + sxtl v6.4s, v5.4h // c mov v0.h[0], wzr mul v0.8h, v0.8h, v4.h[0] dup v16.4s, v2.s[0] dup v17.4s, v2.s[0] - dup v2.8h, v4.h[0] - dup v3.4s, v6.s[0] - shl v2.8h, v2.8h, #3 + dup v2.8h, v4.h[0] // b + dup v3.4s, v6.s[0] // c + sshll v2.4s, v2.4h, #3 // b * 8 saddw v16.4s, v16.4s, v0.4h saddw2 v17.4s, v17.4s, v0.8h - saddw v3.4s, v3.4s, v2.4h + sub v3.4s, v3.4s, v2.4s mov w3, #16 mvni v4.8h, #0xFC, lsl #8 // 1023 for clipping 1: sqshrun v0.4h, v16.4s, #5 sqshrun2 v0.8h, v17.4s, #5 - saddw v16.4s, v16.4s, v2.4h - saddw v17.4s, v17.4s, v2.4h + add v16.4s, v16.4s, v2.4s + add v17.4s, v17.4s, v2.4s sqshrun v1.4h, v16.4s, #5 sqshrun2 v1.8h, v17.4s, #5 add v16.4s, v16.4s, v3.4s @@ -595,12 +594,11 @@ function ff_pred8x8_plane_neon_10, export=1 ssubl v2.4s, v2.4h, v3.4h ext v0.16b, v0.16b, v0.16b, #14 mov v0.h[0], wzr - mul v0.8h, v0.8h, v5.h[0] dup v1.4s, v2.s[0] dup v2.4s, v2.s[0] dup v3.8h, v5.h[1] - saddw v1.4s, v1.4s, v0.4h - saddw2 v2.4s, v2.4s, v0.8h + smlal v1.4s, v0.4h, v5.h[0] + smlal2 v2.4s, v0.8h, v5.h[0] mov w3, #8 mvni v4.8h, #0xFC, lsl #8 // 1023 for clipping 1: diff --git a/libavcodec/aarch64/vp9mc_neon.S b/libavcodec/aarch64/vp9mc_neon.S index abf2bae9db..38f44ca56d 100644 --- a/libavcodec/aarch64/vp9mc_neon.S +++ b/libavcodec/aarch64/vp9mc_neon.S @@ -230,6 +230,9 @@ function \type\()_8tap_\size\()h_\idx1\idx2 // reduced dst stride .if \size >= 16 sub x1, x1, x5 +.elseif \size == 4 + add x12, x2, #8 + add x13, x7, #8 .endif // size >= 16 loads two qwords and increments x2, // for size 4/8 it's enough with one qword and no @@ -248,9 +251,14 @@ function \type\()_8tap_\size\()h_\idx1\idx2 .if \size >= 16 ld1 {v4.8b, v5.8b, v6.8b}, [x2], #24 ld1 {v16.8b, v17.8b, v18.8b}, [x7], #24 -.else +.elseif \size == 8 ld1 {v4.8b, v5.8b}, [x2] ld1 {v16.8b, v17.8b}, [x7] +.else // \size == 4 + ld1 {v4.8b}, [x2] + ld1 {v16.8b}, [x7] + ld1 {v5.s}[0], [x12], x3 + ld1 {v17.s}[0], [x13], x3 .endif uxtl v4.8h, v4.8b uxtl v5.8h, v5.8b diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c index 13b8d3b7d8..283139288c 100644 --- a/libavcodec/ac3_parser.c +++ b/libavcodec/ac3_parser.c @@ -204,7 +204,9 @@ int av_ac3_parse_header(const uint8_t *buf, size_t size, AC3HeaderInfo hdr; int err; - init_get_bits8(&gb, buf, size); + err = init_get_bits8(&gb, buf, size); + if (err < 0) + return AVERROR_INVALIDDATA; err = ff_ac3_parse_header(&gb, &hdr); if (err < 0) return AVERROR_INVALIDDATA; diff --git a/libavcodec/adts_parser.c b/libavcodec/adts_parser.c index f2e155fc99..28ad5ef5eb 100644 --- a/libavcodec/adts_parser.c +++ b/libavcodec/adts_parser.c @@ -27,9 +27,14 @@ int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames) { #if CONFIG_ADTS_HEADER + uint8_t tmpbuf[AV_AAC_ADTS_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; GetBitContext gb; AACADTSHeaderInfo hdr; - int err = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE); + int err; + if (!buf) + return AVERROR(EINVAL); + memcpy(tmpbuf, buf, AV_AAC_ADTS_HEADER_SIZE); + err = init_get_bits8(&gb, tmpbuf, AV_AAC_ADTS_HEADER_SIZE); if (err < 0) return err; err = ff_adts_header_parse(&gb, &hdr); diff --git a/libavcodec/aic.c b/libavcodec/aic.c index f8b0f60354..48a125d956 100644 --- a/libavcodec/aic.c +++ b/libavcodec/aic.c @@ -466,8 +466,7 @@ static av_cold int aic_decode_init(AVCodecContext *avctx) } } - ctx->slice_data = av_malloc_array(ctx->slice_width, AIC_BAND_COEFFS - * sizeof(*ctx->slice_data)); + ctx->slice_data = av_calloc(ctx->slice_width, AIC_BAND_COEFFS * sizeof(*ctx->slice_data)); if (!ctx->slice_data) { av_log(avctx, AV_LOG_ERROR, "Error allocating slice buffer\n"); diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index c64d1032a4..0b78f75ea6 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -2110,9 +2110,9 @@ static av_cold int decode_init(AVCodecContext *avctx) if (sconf->floating) { ctx->acf = av_malloc_array(channels, sizeof(*ctx->acf)); - ctx->shift_value = av_malloc_array(channels, sizeof(*ctx->shift_value)); - ctx->last_shift_value = av_malloc_array(channels, sizeof(*ctx->last_shift_value)); - ctx->last_acf_mantissa = av_malloc_array(channels, sizeof(*ctx->last_acf_mantissa)); + ctx->shift_value = av_calloc(channels, sizeof(*ctx->shift_value)); + ctx->last_shift_value = av_calloc(channels, sizeof(*ctx->last_shift_value)); + ctx->last_acf_mantissa = av_calloc(channels, sizeof(*ctx->last_acf_mantissa)); ctx->raw_mantissa = av_calloc(channels, sizeof(*ctx->raw_mantissa)); ctx->larray = av_malloc_array(ctx->cur_frame_length * 4, sizeof(*ctx->larray)); diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c index 9d75b972fa..21a730b835 100644 --- a/libavcodec/amrwbdec.c +++ b/libavcodec/amrwbdec.c @@ -26,6 +26,7 @@ #include "config.h" +#include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" #include "libavutil/lfg.h" @@ -554,6 +555,8 @@ static void decode_fixed_vector(float *fixed_vector, const uint16_t *pulse_hi, decode_6p_track(sig_pos[i], (int) pulse_lo[i] + ((int) pulse_hi[i] << 11), 4, 1); break; + default: + av_assert2(0); } memset(fixed_vector, 0, sizeof(float) * AMRWB_SFR_SIZE); diff --git a/libavcodec/apac.c b/libavcodec/apac.c index b6cb6c669e..98c34b9996 100644 --- a/libavcodec/apac.c +++ b/libavcodec/apac.c @@ -130,7 +130,7 @@ static int apac_decode(AVCodecContext *avctx, AVFrame *frame, APACContext *s = avctx->priv_data; GetBitContext *gb = &s->gb; int ret, n, buf_size, input_buf_size; - const uint8_t *buf; + uint8_t *buf; int nb_samples; if (!pkt->size && s->bitstream_size <= 0) { @@ -160,6 +160,7 @@ static int apac_decode(AVCodecContext *avctx, AVFrame *frame, buf = &s->bitstream[s->bitstream_index]; buf_size += s->bitstream_size; s->bitstream_size = buf_size; + memset(buf + buf_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); frame->nb_samples = s->bitstream_size * 16 * 8; if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index 0f48bdff77..7d96182d0c 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -1286,7 +1286,7 @@ static void predictor_decode_stereo_3950(APEContext *ctx, int count) int32_t left = a1 - (unsigned)(a0 / 2); int32_t right = left + (unsigned)a0; - if (FFMAX(FFABS(left), FFABS(right)) > (1<<23)) { + if (FFMIN(FFNABS(left), FFNABS(right)) < -(1<<23)) { ctx->interim_mode = !interim_mode; av_log(ctx->avctx, AV_LOG_VERBOSE, "Interim mode: %d\n", ctx->interim_mode); break; diff --git a/libavcodec/arm/mlpdsp_armv5te.S b/libavcodec/arm/mlpdsp_armv5te.S index 4f9aa485fd..d31568611c 100644 --- a/libavcodec/arm/mlpdsp_armv5te.S +++ b/libavcodec/arm/mlpdsp_armv5te.S @@ -229,7 +229,7 @@ A .endif .endif // Begin loop -01: +1: .if TOTAL_TAPS == 0 // Things simplify a lot in this case // In fact this could be pipelined further if it's worth it... @@ -241,7 +241,7 @@ A .endif str ST0, [PST, #-4]! str ST0, [PST, #4 * (MAX_BLOCKSIZE + MAX_FIR_ORDER)] str ST0, [PSAMP], #4 * MAX_CHANNELS - bne 01b + bne 1b .else .if \fir_taps & 1 .set LOAD_REG, 1 @@ -333,7 +333,7 @@ T orr AC0, AC0, AC1 str ST3, [PST, #-4]! str ST2, [PST, #4 * (MAX_BLOCKSIZE + MAX_FIR_ORDER)] str ST3, [PSAMP], #4 * MAX_CHANNELS - bne 01b + bne 1b .endif b 99f diff --git a/libavcodec/arm/vp9mc_neon.S b/libavcodec/arm/vp9mc_neon.S index bd8cda7c30..2ec729bb31 100644 --- a/libavcodec/arm/vp9mc_neon.S +++ b/libavcodec/arm/vp9mc_neon.S @@ -279,11 +279,13 @@ function \type\()_8tap_\size\()h_\idx1\idx2 sub r1, r1, r5 .endif @ size >= 16 loads two qwords and increments r2, - @ for size 4/8 it's enough with one qword and no - @ postincrement + @ size 4 loads 1 d word, increments r2 and loads 1 32-bit lane + @ for size 8 it's enough with one qword and no postincrement .if \size >= 16 sub r3, r3, r5 sub r3, r3, #8 +.elseif \size == 4 + sub r3, r3, #8 .endif @ Load the filter vector vld1.16 {q0}, [r12,:128] @@ -295,9 +297,14 @@ function \type\()_8tap_\size\()h_\idx1\idx2 .if \size >= 16 vld1.8 {d18, d19, d20}, [r2]! vld1.8 {d24, d25, d26}, [r7]! -.else +.elseif \size == 8 vld1.8 {q9}, [r2] vld1.8 {q12}, [r7] +.else @ size == 4 + vld1.8 {d18}, [r2]! + vld1.8 {d24}, [r7]! + vld1.32 {d19[0]}, [r2] + vld1.32 {d25[0]}, [r7] .endif vmovl.u8 q8, d18 vmovl.u8 q9, d19 diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c index 5b84f0c6d6..91f2e50b05 100644 --- a/libavcodec/atrac9dec.c +++ b/libavcodec/atrac9dec.c @@ -801,7 +801,9 @@ static int atrac9_decode_frame(AVCodecContext *avctx, AVFrame *frame, if (ret < 0) return ret; - init_get_bits8(&gb, avpkt->data, avpkt->size); + ret = init_get_bits8(&gb, avpkt->data, avpkt->size); + if (ret < 0) + return ret; for (int i = 0; i < frames; i++) { for (int j = 0; j < s->block_config->count; j++) { @@ -921,7 +923,9 @@ static av_cold int atrac9_decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } - init_get_bits8(&gb, avctx->extradata + 4, avctx->extradata_size); + err = init_get_bits8(&gb, avctx->extradata + 4, avctx->extradata_size); + if (err < 0) + return err; if (get_bits(&gb, 8) != 0xFE) { av_log(avctx, AV_LOG_ERROR, "Incorrect magic byte!\n"); diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 32a795e758..32c2379a45 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -358,6 +358,30 @@ static void coded_lossless_param(AV1DecContext *s) } } +static void order_hint_info(AV1DecContext *s) +{ + const AV1RawFrameHeader *header = s->raw_frame_header; + const AV1RawSequenceHeader *seq = s->raw_seq; + AV1Frame *frame = &s->cur_frame; + + frame->order_hint = header->order_hint; + + for (int i = 0; i < AV1_REFS_PER_FRAME; i++) { + int ref_name = i + AV1_REF_FRAME_LAST; + int ref_slot = header->ref_frame_idx[i]; + int ref_order_hint = s->ref[ref_slot].order_hint; + + frame->order_hints[ref_name] = ref_order_hint; + if (!seq->enable_order_hint) { + frame->ref_frame_sign_bias[ref_name] = 0; + } else { + frame->ref_frame_sign_bias[ref_name] = + get_relative_dist(seq, ref_order_hint, + frame->order_hint) > 0; + } + } +} + static void load_grain_params(AV1DecContext *s) { const AV1RawFrameHeader *header = s->raw_frame_header; @@ -444,7 +468,7 @@ static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_gro static enum AVPixelFormat get_sw_pixel_format(void *logctx, const AV1RawSequenceHeader *seq) { - uint8_t bit_depth; + int bit_depth; enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE; if (seq->seq_profile == 2 && seq->color_config.high_bitdepth) @@ -468,7 +492,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx, else if (bit_depth == 12) pix_fmt = AV_PIX_FMT_YUV444P12; else - av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n"); + av_assert0(0); } else if (seq->color_config.subsampling_x == 1 && seq->color_config.subsampling_y == 0) { if (bit_depth == 8) @@ -478,7 +502,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx, else if (bit_depth == 12) pix_fmt = AV_PIX_FMT_YUV422P12; else - av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n"); + av_assert0(0); } else if (seq->color_config.subsampling_x == 1 && seq->color_config.subsampling_y == 1) { if (bit_depth == 8) @@ -488,7 +512,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx, else if (bit_depth == 12) pix_fmt = AV_PIX_FMT_YUV420P12; else - av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n"); + av_assert0(0); } } else { if (bit_depth == 8) @@ -498,7 +522,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx, else if (bit_depth == 12) pix_fmt = AV_PIX_FMT_GRAY12; else - av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n"); + av_assert0(0); } return pix_fmt; @@ -700,6 +724,14 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s sizeof(dst->film_grain)); dst->coded_lossless = src->coded_lossless; + dst->order_hint = src->order_hint; + memcpy(dst->ref_frame_sign_bias, src->ref_frame_sign_bias, + sizeof(dst->ref_frame_sign_bias)); + memcpy(dst->order_hints, src->order_hints, + sizeof(dst->order_hints)); + + dst->force_integer_mv = src->force_integer_mv; + return 0; fail: @@ -1255,8 +1287,14 @@ static int get_current_frame(AVCodecContext *avctx) global_motion_params(s); skip_mode_params(s); coded_lossless_param(s); + order_hint_info(s); load_grain_params(s); + s->cur_frame.force_integer_mv = + s->raw_frame_header->force_integer_mv || + s->raw_frame_header->frame_type == AV1_FRAME_KEY || + s->raw_frame_header->frame_type == AV1_FRAME_INTRA_ONLY; + return ret; } diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h index 336eb61359..b903b359c5 100644 --- a/libavcodec/av1dec.h +++ b/libavcodec/av1dec.h @@ -53,6 +53,20 @@ typedef struct AV1Frame { AV1RawFilmGrainParams film_grain; uint8_t coded_lossless; + + // OrderHint for this frame. + uint8_t order_hint; + // RefFrameSignBias[] used when decoding this frame. + uint8_t ref_frame_sign_bias[AV1_TOTAL_REFS_PER_FRAME]; + // OrderHints[] when this is the current frame, otherwise + // SavedOrderHints[s][] when is the reference frame in slot s. + uint8_t order_hints[AV1_TOTAL_REFS_PER_FRAME]; + + // force_integer_mv value at the end of the frame header parsing. + // This is not the same as the syntax element value in + // raw_frame_header because the specification parsing tables + // override the value on intra frames. + uint8_t force_integer_mv; } AV1Frame; typedef struct TileGroupInfo { diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 83dc487251..9c438cedaf 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1175,6 +1175,10 @@ typedef struct AVCodecContext { * this callback and filled with the extra buffers if there are more * buffers than buf[] can hold. extended_buf will be freed in * av_frame_unref(). + * Decoders will generally initialize the whole buffer before it is output + * but it can in rare error conditions happen that uninitialized data is passed + * through. \important The buffers returned by get_buffer* should thus not contain sensitive + * data. * * If AV_CODEC_CAP_DR1 is not set then get_buffer2() must call * avcodec_default_get_buffer2() instead of providing buffers allocated by diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c index 200134f91d..0d68ab1d00 100644 --- a/libavcodec/avs2_parser.c +++ b/libavcodec/avs2_parser.c @@ -72,13 +72,15 @@ static void parse_avs2_seq_header(AVCodecParserContext *s, const uint8_t *buf, unsigned aspect_ratio; unsigned frame_rate_code; int low_delay; + av_unused int ret; // update buf_size_min if parse more deeper const int buf_size_min = 15; if (buf_size < buf_size_min) return; - init_get_bits8(&gb, buf, buf_size_min); + ret = init_get_bits8(&gb, buf, buf_size_min); + av_assert1(ret >= 0); s->key_frame = 1; s->pict_type = AV_PICTURE_TYPE_I; diff --git a/libavcodec/avs3_parser.c b/libavcodec/avs3_parser.c index a819b5783d..ea495b1c7c 100644 --- a/libavcodec/avs3_parser.c +++ b/libavcodec/avs3_parser.c @@ -73,7 +73,8 @@ static void parse_avs3_nal_units(AVCodecParserContext *s, const uint8_t *buf, GetBitContext gb; int profile, ratecode, low_delay; - init_get_bits8(&gb, buf + 4, buf_size - 4); + av_unused int ret = init_get_bits(&gb, buf + 4, 100); + av_assert1(ret >= 0); s->key_frame = 1; s->pict_type = AV_PICTURE_TYPE_I; diff --git a/libavcodec/bitstream_template.h b/libavcodec/bitstream_template.h index 4f3d07275f..c8e4a5131e 100644 --- a/libavcodec/bitstream_template.h +++ b/libavcodec/bitstream_template.h @@ -536,7 +536,8 @@ static inline int BS_FUNC(read_vlc)(BSCTX *bc, const VLCElem *table, static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t dst[8], const VLC_MULTI_ELEM *const Jtable, const VLCElem *const table, - const int bits, const int max_depth) + const int bits, const int max_depth, + const int symbols_size) { unsigned idx = BS_FUNC(peek)(bc, bits); int ret, nb_bits, code, n = Jtable[idx].len; @@ -554,7 +555,10 @@ static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t dst[8], code = BS_FUNC(priv_set_idx)(bc, code, &n, &nb_bits, table); } } - AV_WN16(dst, code); + if (symbols_size == 1) + *dst = code; + else + AV_WN16(dst, code); ret = n > 0; } BS_FUNC(priv_skip_remaining)(bc, n); diff --git a/libavcodec/bsf/h264_mp4toannexb.c b/libavcodec/bsf/h264_mp4toannexb.c index 120241c892..92af6a6881 100644 --- a/libavcodec/bsf/h264_mp4toannexb.c +++ b/libavcodec/bsf/h264_mp4toannexb.c @@ -208,6 +208,49 @@ static int h264_mp4toannexb_save_ps(uint8_t **dst, int *dst_size, return 0; } +static int h264_mp4toannexb_filter_ps(H264BSFContext *s, + const uint8_t *buf, + const uint8_t *buf_end) +{ + int sps_count = 0; + int pps_count = 0; + uint8_t unit_type; + + do { + uint32_t nal_size = 0; + + /* possible overread ok due to padding */ + for (int i = 0; i < s->length_size; i++) + nal_size = (nal_size << 8) | buf[i]; + + buf += s->length_size; + + /* This check requires the cast as the right side might + * otherwise be promoted to an unsigned value. */ + if ((int64_t)nal_size > buf_end - buf) + return AVERROR_INVALIDDATA; + + if (!nal_size) + continue; + + unit_type = *buf & 0x1f; + + if (unit_type == H264_NAL_SPS) { + h264_mp4toannexb_save_ps(&s->sps, &s->sps_size, &s->sps_buf_size, buf, + nal_size, !sps_count); + sps_count++; + } else if (unit_type == H264_NAL_PPS) { + h264_mp4toannexb_save_ps(&s->pps, &s->pps_size, &s->pps_buf_size, buf, + nal_size, !pps_count); + pps_count++; + } + + buf += nal_size; + } while (buf < buf_end); + + return 0; +} + static int h264_mp4toannexb_init(AVBSFContext *ctx) { int extra_size = ctx->par_in->extradata_size; @@ -263,14 +306,14 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) } buf_end = in->data + in->size; + ret = h264_mp4toannexb_filter_ps(s, in->data, buf_end); + if (ret < 0) + goto fail; #define LOG_ONCE(...) \ if (j) \ av_log(__VA_ARGS__) for (int j = 0; j < 2; j++) { - int sps_count = 0; - int pps_count = 0; - buf = in->data; new_idr = s->new_idr; sps_seen = s->idr_sps_seen; @@ -301,18 +344,8 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) if (unit_type == H264_NAL_SPS) { sps_seen = new_idr = 1; - if (!j) { - h264_mp4toannexb_save_ps(&s->sps, &s->sps_size, &s->sps_buf_size, - buf, nal_size, !sps_count); - sps_count++; - } } else if (unit_type == H264_NAL_PPS) { pps_seen = new_idr = 1; - if (!j) { - h264_mp4toannexb_save_ps(&s->pps, &s->pps_size, &s->pps_buf_size, - buf, nal_size, !pps_count); - pps_count++; - } /* if SPS has not been seen yet, prepend the AVCC one to PPS */ if (!sps_seen) { if (!s->sps_size) { diff --git a/libavcodec/bsf/media100_to_mjpegb.c b/libavcodec/bsf/media100_to_mjpegb.c index 6e117ae20f..4b2dc1a35a 100644 --- a/libavcodec/bsf/media100_to_mjpegb.c +++ b/libavcodec/bsf/media100_to_mjpegb.c @@ -148,6 +148,7 @@ second_field: AV_WB32(out->data + second_field_offset + 36, sod_offset[1] - second_field_offset); out->size = bytestream2_tell_p(&pb); + memset(out->data + out->size, 0, AV_INPUT_BUFFER_PADDING_SIZE); ret = av_packet_copy_props(out, in); if (ret < 0) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index 1d9ac5ab44..458381f038 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -36,7 +36,7 @@ static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc, CBS_TRACE_READ_START(); zeroes = 0; - while (1) { + while (zeroes < 32) { if (get_bits_left(gbc) < 1) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid uvlc code at " "%s: bitstream ended.\n", name); @@ -49,10 +49,18 @@ static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc, } if (zeroes >= 32) { - // Note that the spec allows an arbitrarily large number of - // zero bits followed by a one bit in this case, but the - // libaom implementation does not support it. - value = MAX_UINT_BITS(32); + // The spec allows at least thirty-two zero bits followed by a + // one to mean 2^32-1, with no constraint on the number of + // zeroes. The libaom reference decoder does not match this, + // instead reading thirty-two zeroes but not the following one + // to mean 2^32-1. These two interpretations are incompatible + // and other implementations may follow one or the other. + // Therefore we reject thirty-two zeroes because the intended + // behaviour is not clear. + av_log(ctx->log_ctx, AV_LOG_ERROR, "Thirty-two zero bits in " + "%s uvlc code: considered invalid due to conflicting " + "standard and reference decoder behaviour.\n", name); + return AVERROR_INVALIDDATA; } else { if (get_bits_left(gbc) < zeroes) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid uvlc code at " @@ -301,7 +309,7 @@ static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pb return AVERROR(ENOSPC); if (len > 0) - put_bits(pbc, len, (1 << len) - 1 - (value != range_max)); + put_bits(pbc, len, (1U << len) - 1 - (value != range_max)); CBS_TRACE_WRITE_END_NO_SUBSCRIPTS(); diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 8e4af7b2cc..db803ea351 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -708,7 +708,11 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, start = bytestream2_tell(&gbc); for(i = 0; i < num_nalus; i++) { + if (bytestream2_get_bytes_left(&gbc) < 2) + return AVERROR_INVALIDDATA; size = bytestream2_get_be16(&gbc); + if (bytestream2_get_bytes_left(&gbc) < size) + return AVERROR_INVALIDDATA; bytestream2_skip(&gbc, size); } end = bytestream2_tell(&gbc); diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c index 0aae9fdfd5..7907f9d5c7 100644 --- a/libavcodec/cbs_h266_syntax_template.c +++ b/libavcodec/cbs_h266_syntax_template.c @@ -790,6 +790,21 @@ static int FUNC(vps) (CodedBitstreamContext *ctx, RWContext *rw, infer(vps_each_layer_is_an_ols_flag, 1); infer(vps_num_ptls_minus1, 0); } + + for (i = 0; i <= current->vps_num_ptls_minus1; i++) { + if (i > 0) + flags(vps_pt_present_flag[i], 1, i); + else + infer(vps_pt_present_flag[i], 1); + + if (!current->vps_default_ptl_dpb_hrd_max_tid_flag) + us(3, vps_ptl_max_tid[i], 0, current->vps_max_sublayers_minus1, 1, i); + else + infer(vps_ptl_max_tid[i], current->vps_max_sublayers_minus1); + } + while (byte_alignment(rw) != 0) + fixed(1, vps_ptl_alignment_zero_bit, 0); + { //calc NumMultiLayerOlss int m; @@ -915,19 +930,6 @@ static int FUNC(vps) (CodedBitstreamContext *ctx, RWContext *rw, return AVERROR_INVALIDDATA; } - for (i = 0; i <= current->vps_num_ptls_minus1; i++) { - if (i > 0) - flags(vps_pt_present_flag[i], 1, i); - else - infer(vps_pt_present_flag[i], 1); - - if (!current->vps_default_ptl_dpb_hrd_max_tid_flag) - us(3, vps_ptl_max_tid[i], 0, current->vps_max_sublayers_minus1, 1, i); - else - infer(vps_ptl_max_tid[i], current->vps_max_sublayers_minus1); - } - while (byte_alignment(rw) != 0) - fixed(1, vps_ptl_alignment_zero_bit, 0); for (i = 0; i <= current->vps_num_ptls_minus1; i++) { CHECK(FUNC(profile_tier_level) (ctx, rw, current->vps_profile_tier_level + i, @@ -1616,6 +1618,8 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, ub(7, sps_extension_7bits); if (current->sps_range_extension_flag) { + if (current->sps_bitdepth_minus8 <= 10 - 8) + return AVERROR_INVALIDDATA; CHECK(FUNC(sps_range_extension)(ctx, rw, current)); } else { infer(sps_extended_precision_flag, 0); @@ -3221,19 +3225,27 @@ static int FUNC(slice_header) (CodedBitstreamContext *ctx, RWContext *rw, flag(sh_cabac_init_flag); else infer(sh_cabac_init_flag, 0); - if (ph->ph_temporal_mvp_enabled_flag && !pps->pps_rpl_info_in_ph_flag) { - if (current->sh_slice_type == VVC_SLICE_TYPE_B) - flag(sh_collocated_from_l0_flag); - else - infer(sh_collocated_from_l0_flag, 1); - if ((current->sh_collocated_from_l0_flag && - current->num_ref_idx_active[0] > 1) || - (!current->sh_collocated_from_l0_flag && - current->num_ref_idx_active[1] > 1)) { - unsigned int idx = current->sh_collocated_from_l0_flag ? 0 : 1; - ue(sh_collocated_ref_idx, 0, current->num_ref_idx_active[idx] - 1); + if (ph->ph_temporal_mvp_enabled_flag) { + if (!pps->pps_rpl_info_in_ph_flag) { + if (current->sh_slice_type == VVC_SLICE_TYPE_B) + flag(sh_collocated_from_l0_flag); + else + infer(sh_collocated_from_l0_flag, 1); + if ((current->sh_collocated_from_l0_flag && + current->num_ref_idx_active[0] > 1) || + (!current->sh_collocated_from_l0_flag && + current->num_ref_idx_active[1] > 1)) { + unsigned int idx = current->sh_collocated_from_l0_flag ? 0 : 1; + ue(sh_collocated_ref_idx, 0, current->num_ref_idx_active[idx] - 1); + } else { + infer(sh_collocated_ref_idx, 0); + } } else { - infer(sh_collocated_ref_idx, 0); + if (current->sh_slice_type == VVC_SLICE_TYPE_B) + infer(sh_collocated_from_l0_flag, ph->ph_collocated_from_l0_flag); + else + infer(sh_collocated_from_l0_flag, 1); + infer(sh_collocated_ref_idx, ph->ph_collocated_ref_idx); } } if (!pps->pps_wp_info_in_ph_flag && diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c index 5921d624a1..f2aa496610 100644 --- a/libavcodec/cbs_jpeg.c +++ b/libavcodec/cbs_jpeg.c @@ -145,13 +145,13 @@ static int cbs_jpeg_split_fragment(CodedBitstreamContext *ctx, } } else { i = start; - if (i + 2 > frag->data_size) { + if (i > frag->data_size - 2) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid JPEG image: " "truncated at %02x marker.\n", marker); return AVERROR_INVALIDDATA; } length = AV_RB16(frag->data + i); - if (i + length > frag->data_size) { + if (length > frag->data_size - i) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid JPEG image: " "truncated at %02x marker segment.\n", marker); return AVERROR_INVALIDDATA; diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c index 816d06da04..ff99fe32fb 100644 --- a/libavcodec/cbs_vp9.c +++ b/libavcodec/cbs_vp9.c @@ -375,7 +375,7 @@ static int cbs_vp9_split_fragment(CodedBitstreamContext *ctx, superframe_header = frag->data[frag->data_size - 1]; if ((superframe_header & 0xe0) == 0xc0) { - VP9RawSuperframeIndex sfi; + VP9RawSuperframeIndex sfi = {0}; GetBitContext gbc; size_t index_size, pos; int i; diff --git a/libavcodec/cfhdenc.c b/libavcodec/cfhdenc.c index 7169d20a8c..787c2674aa 100644 --- a/libavcodec/cfhdenc.c +++ b/libavcodec/cfhdenc.c @@ -258,8 +258,8 @@ static av_cold int cfhd_encode_init(AVCodecContext *avctx) if (ret < 0) return ret; - if (avctx->height < 4) { - av_log(avctx, AV_LOG_ERROR, "Height must be >= 4.\n"); + if (avctx->height < 32) { + av_log(avctx, AV_LOG_ERROR, "Height must be >= 32.\n"); return AVERROR_INVALIDDATA; } @@ -286,7 +286,7 @@ static av_cold int cfhd_encode_init(AVCodecContext *avctx) s->plane[i].dwt_buf = av_calloc(h8 * 8 * w8 * 8, sizeof(*s->plane[i].dwt_buf)); s->plane[i].dwt_tmp = - av_malloc_array(h8 * 8 * w8 * 8, sizeof(*s->plane[i].dwt_tmp)); + av_calloc(h8 * 8 * w8 * 8, sizeof(*s->plane[i].dwt_tmp)); if (!s->plane[i].dwt_buf || !s->plane[i].dwt_tmp) return AVERROR(ENOMEM); @@ -553,7 +553,7 @@ static int cfhd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, width, height * 2); } - ret = ff_alloc_packet(avctx, pkt, 256LL + s->planes * (2LL * avctx->width * (avctx->height + 15) + 2048LL)); + ret = ff_alloc_packet(avctx, pkt, 256LL + s->planes * (4LL * avctx->width * (avctx->height + 15) + 2048LL)); if (ret < 0) return ret; @@ -761,7 +761,6 @@ static int cfhd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, } else if (count > 0) { count = put_runcode(pb, count, rb); } - put_bits(pb, cb[index].size, cb[index].bits); } diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c index 212cb97d77..790ea01d10 100644 --- a/libavcodec/codec_par.c +++ b/libavcodec/codec_par.c @@ -250,6 +250,7 @@ int avcodec_parameters_to_context(AVCodecContext *codec, } av_freep(&codec->extradata); + codec->extradata_size = 0; if (par->extradata) { codec->extradata = av_mallocz(par->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!codec->extradata) diff --git a/libavcodec/cri.c b/libavcodec/cri.c index 990e52ac99..7297c0350f 100644 --- a/libavcodec/cri.c +++ b/libavcodec/cri.c @@ -234,10 +234,14 @@ static int cri_decode_frame(AVCodecContext *avctx, AVFrame *p, s->data_size = length; goto skip; case 105: + if (length <= 0) + return AVERROR_INVALIDDATA; hflip = bytestream2_get_byte(gb) != 0; length--; goto skip; case 106: + if (length <= 0) + return AVERROR_INVALIDDATA; vflip = bytestream2_get_byte(gb) != 0; length--; goto skip; diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 34bcb7cc64..ac18544b2e 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -428,7 +428,8 @@ FF_ENABLE_DEPRECATION_WARNINGS } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { ret = !got_frame ? AVERROR(EAGAIN) : discard_samples(avctx, frame, discarded_samples); - } + } else + av_assert0(0); if (ret == AVERROR(EAGAIN)) av_frame_unref(frame); diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index b5553a0c86..e3107414c8 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -240,7 +240,7 @@ static int get_opcodes(GetByteContext *gb, uint32_t *table, uint8_t *dst, int op size_in_bits = bytestream2_get_le32(gb); endoffset = ((size_in_bits + 7) >> 3) - 4; - if (endoffset <= 0 || bytestream2_get_bytes_left(gb) < endoffset) + if ((int)endoffset <= 0 || bytestream2_get_bytes_left(gb) < endoffset) return AVERROR_INVALIDDATA; offset = endoffset; diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c index 59025633f7..c9526b2e2f 100644 --- a/libavcodec/dxva2.c +++ b/libavcodec/dxva2.c @@ -117,7 +117,7 @@ static int dxva_get_decoder_configuration(AVCodecContext *avctx, for (i = 0; i < cfg_count; i++) { unsigned score; - UINT ConfigBitstreamRaw; + UINT ConfigBitstreamRaw = 0; GUID guidConfigBitstreamEncryption; #if CONFIG_D3D11VA @@ -268,7 +268,7 @@ static int dxva_get_decoder_guid(AVCodecContext *avctx, void *service, void *sur *decoder_guid = ff_GUID_NULL; for (i = 0; dxva_modes[i].guid; i++) { const dxva_mode *mode = &dxva_modes[i]; - int validate; + int validate = 0; if (!dxva_check_codec_compatibility(avctx, mode)) continue; @@ -805,7 +805,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, unsigned type, const void *data, unsigned size, unsigned mb_count) { - void *dxva_data; + void *dxva_data = NULL; unsigned dxva_size; int result; HRESULT hr = 0; @@ -827,7 +827,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, type, (unsigned)hr); return -1; } - if (size <= dxva_size) { + if (dxva_data && size <= dxva_size) { memcpy(dxva_data, data, size); #if CONFIG_D3D11VA @@ -905,7 +905,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, #endif DECODER_BUFFER_DESC *buffer = NULL, *buffer_slice = NULL; int result, runs = 0; - HRESULT hr; + HRESULT hr = -1; unsigned type; FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx); diff --git a/libavcodec/eacmv.c b/libavcodec/eacmv.c index 43dba20fae..15d3550cb8 100644 --- a/libavcodec/eacmv.c +++ b/libavcodec/eacmv.c @@ -194,12 +194,15 @@ static int cmv_decode_frame(AVCodecContext *avctx, AVFrame *frame, if ((ret = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0) return ret; + buf += EA_PREAMBLE_SIZE; + if (!(buf[0]&1) && buf_end - buf < s->width * s->height * (int64_t)(100 - s->avctx->discard_damaged_percentage) / 100) + return AVERROR_INVALIDDATA; + if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) return ret; memcpy(frame->data[1], s->palette, AVPALETTE_SIZE); - buf += EA_PREAMBLE_SIZE; if ((buf[0]&1)) { // subtype cmv_decode_inter(s, frame, buf+2, buf_end); frame->flags &= ~AV_FRAME_FLAG_KEY; diff --git a/libavcodec/eatgq.c b/libavcodec/eatgq.c index 0f0ed3585f..6a19de93f0 100644 --- a/libavcodec/eatgq.c +++ b/libavcodec/eatgq.c @@ -178,7 +178,8 @@ static int tgq_decode_mb(TgqContext *s, GetByteContext *gbyte, dc[4] = bytestream2_get_byte(gbyte); dc[5] = bytestream2_get_byte(gbyte); } else if (mode == 6) { - bytestream2_get_buffer(gbyte, dc, 6); + if (bytestream2_get_buffer(gbyte, dc, 6) != 6) + return AVERROR_INVALIDDATA; } else if (mode == 12) { for (i = 0; i < 6; i++) { dc[i] = bytestream2_get_byte(gbyte); diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 7fc9737e93..caac6c3c3e 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -739,6 +739,11 @@ int ff_encode_preinit(AVCodecContext *avctx) return AVERROR(EINVAL); } + if (avctx->bit_rate < 0) { + av_log(avctx, AV_LOG_ERROR, "The encoder bitrate is negative.\n"); + return AVERROR(EINVAL); + } + if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE && !(avctx->codec->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE)) { av_log(avctx, AV_LOG_ERROR, "The copy_opaque flag is set, but the " diff --git a/libavcodec/exr.c b/libavcodec/exr.c index 5711fbbdcd..cf62953436 100644 --- a/libavcodec/exr.c +++ b/libavcodec/exr.c @@ -334,7 +334,10 @@ static int huf_unpack_enc_table(GetByteContext *gb, return ret; for (; im <= iM; im++) { - uint64_t l = freq[im] = get_bits(&gbit, 6); + int l; + if (get_bits_left(&gbit) < 6) + return AVERROR_INVALIDDATA; + l = freq[im] = get_bits(&gbit, 6); if (l == LONG_ZEROCODE_RUN) { int zerun = get_bits(&gbit, 8) + SHORTEST_LONG_RUN; @@ -1939,7 +1942,7 @@ static int decode_header(EXRContext *s, AVFrame *frame) "preview", 16)) >= 0) { uint32_t pw = bytestream2_get_le32(gb); uint32_t ph = bytestream2_get_le32(gb); - uint64_t psize = pw * ph; + uint64_t psize = pw * (uint64_t)ph; if (psize > INT64_MAX / 4) { ret = AVERROR_INVALIDDATA; goto fail; diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index b6204740ed..2660cae208 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -103,6 +103,13 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f) return 0; } +int ff_need_new_slices(int width, int num_h_slices, int chroma_shift) { + int mpw = 1<num_h_slices * f->num_v_slices; diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 04869da5c9..bbe0839868 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -142,6 +142,7 @@ int ff_ffv1_init_slice_contexts(FFV1Context *f); int ff_ffv1_allocate_initial_states(FFV1Context *f); void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs); int ff_ffv1_close(AVCodecContext *avctx); +int ff_need_new_slices(int width, int num_h_slices, int chroma_shift); static av_always_inline int fold(int diff, int bits) { diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 97877b9106..65404bfb5d 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -363,7 +363,7 @@ static int decode_slice(AVCodecContext *c, void *arg) if (fs->ac != AC_GOLOMB_RICE && f->version > 2) { int v; get_rac(&fs->c, (uint8_t[]) { 129 }); - v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec; + v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*!!f->ec; if (v) { av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v); fs->slice_damaged = 1; diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index e510abf6ff..7f0215847b 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -199,7 +199,7 @@ static av_always_inline av_flatten void put_symbol_inline(RangeCoder *c, } while (0) if (v) { - const int a = FFABS(v); + const unsigned a = is_signed ? FFABS(v) : v; const int e = av_log2(a); put_rac(c, state + 0, 0); if (e <= 9) { @@ -526,6 +526,11 @@ static av_cold int encode_init(AVCodecContext *avctx) avctx->slices > 1) s->version = FFMAX(s->version, 2); + if ((avctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) && s->ac == AC_GOLOMB_RICE) { + av_log(avctx, AV_LOG_ERROR, "2 Pass mode is not possible with golomb coding\n"); + return AVERROR(EINVAL); + } + // Unspecified level & slices, we choose version 1.2+ to ensure multithreaded decodability if (avctx->slices == 0 && avctx->level < 0 && avctx->width * avctx->height > 720*576) s->version = FFMAX(s->version, 2); @@ -550,7 +555,7 @@ static av_cold int encode_init(AVCodecContext *avctx) s->version = FFMAX(s->version, 3); if ((s->version == 2 || s->version>3) && avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { - av_log(avctx, AV_LOG_ERROR, "Version 2 needed for requested features but version 2 is experimental and not enabled\n"); + av_log(avctx, AV_LOG_ERROR, "Version 2 or 4 needed for requested features but version 2 or 4 is experimental and not enabled\n"); return AVERROR_INVALIDDATA; } @@ -722,19 +727,21 @@ static av_cold int encode_init(AVCodecContext *avctx) s->quant_tables[1][2][i]= 11*11*quant5 [i]; s->quant_tables[1][3][i]= 5*11*11*quant5 [i]; s->quant_tables[1][4][i]= 5*5*11*11*quant5 [i]; + s->context_count[0] = (11 * 11 * 11 + 1) / 2; + s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2; } else { s->quant_tables[0][0][i]= quant9_10bit[i]; - s->quant_tables[0][1][i]= 11*quant9_10bit[i]; - s->quant_tables[0][2][i]= 11*11*quant9_10bit[i]; + s->quant_tables[0][1][i]= 9*quant9_10bit[i]; + s->quant_tables[0][2][i]= 9*9*quant9_10bit[i]; s->quant_tables[1][0][i]= quant9_10bit[i]; - s->quant_tables[1][1][i]= 11*quant9_10bit[i]; - s->quant_tables[1][2][i]= 11*11*quant5_10bit[i]; - s->quant_tables[1][3][i]= 5*11*11*quant5_10bit[i]; - s->quant_tables[1][4][i]= 5*5*11*11*quant5_10bit[i]; + s->quant_tables[1][1][i]= 9*quant9_10bit[i]; + s->quant_tables[1][2][i]= 9*9*quant5_10bit[i]; + s->quant_tables[1][3][i]= 5*9*9*quant5_10bit[i]; + s->quant_tables[1][4][i]= 5*5*9*9*quant5_10bit[i]; + s->context_count[0] = (9 * 9 * 9 + 1) / 2; + s->context_count[1] = (9 * 9 * 5 * 5 * 5 + 1) / 2; } } - s->context_count[0] = (11 * 11 * 11 + 1) / 2; - s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2; memcpy(s->quant_table, s->quant_tables[s->context_model], sizeof(s->quant_table)); @@ -866,6 +873,10 @@ static av_cold int encode_init(AVCodecContext *avctx) continue; if (maxw * maxh * (int64_t)(s->bits_per_raw_sample+1) * plane_count > 8<<24) continue; + if (s->version < 4) + if ( ff_need_new_slices(avctx->width , s->num_h_slices, s->chroma_h_shift) + ||ff_need_new_slices(avctx->height, s->num_v_slices, s->chroma_v_shift)) + continue; if (avctx->slices == s->num_h_slices * s->num_v_slices && avctx->slices <= MAX_SLICES || !avctx->slices) goto slices_ok; } @@ -914,8 +925,8 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs) put_symbol(c, state, (fs->slice_x +1)*f->num_h_slices / f->width , 0); put_symbol(c, state, (fs->slice_y +1)*f->num_v_slices / f->height , 0); - put_symbol(c, state, (fs->slice_width +1)*f->num_h_slices / f->width -1, 0); - put_symbol(c, state, (fs->slice_height+1)*f->num_v_slices / f->height-1, 0); + put_symbol(c, state, 0, 0); + put_symbol(c, state, 0, 0); for (j=0; jplane_count; j++) { put_symbol(c, state, f->plane[j].quant_table_index, 0); av_assert0(f->plane[j].quant_table_index == f->context_model); diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c index bd91cc1a05..99460e7ea6 100644 --- a/libavcodec/flac_parser.c +++ b/libavcodec/flac_parser.c @@ -519,6 +519,8 @@ static int check_header_mismatch(FLACParseContext *fpc, for (i = 0; i < FLAC_MAX_SEQUENTIAL_HEADERS && curr != child; i++) curr = curr->next; + av_assert0(i < FLAC_MAX_SEQUENTIAL_HEADERS); + if (header->link_penalty[i] < FLAC_HEADER_CRC_FAIL_PENALTY || header->link_penalty[i] == FLAC_HEADER_NOT_PENALIZED_YET) { FLACHeaderMarker *start, *end; diff --git a/libavcodec/fmvc.c b/libavcodec/fmvc.c index 5e26a541ca..a9e5afd17b 100644 --- a/libavcodec/fmvc.c +++ b/libavcodec/fmvc.c @@ -100,7 +100,6 @@ static int decode_type2(GetByteContext *gb, PutByteContext *pb) continue; } } - repeat = 0; } repeat = 1; } diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index cfcf97c021..fe2f6378b4 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -667,7 +667,8 @@ static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, static inline int get_vlc_multi(GetBitContext *s, uint8_t *dst, const VLC_MULTI_ELEM *const Jtable, const VLCElem *const table, - const int bits, const int max_depth) + const int bits, const int max_depth, + const int symbols_size) { dst[0] = get_vlc2(s, table, bits, max_depth); return 1; diff --git a/libavcodec/get_buffer.c b/libavcodec/get_buffer.c index 9b35fde7c6..1f691334f0 100644 --- a/libavcodec/get_buffer.c +++ b/libavcodec/get_buffer.c @@ -146,7 +146,10 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) if (ret < 0) goto fail; - pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL); + pool->pools[0] = av_buffer_pool_init(pool->linesize[0], + CONFIG_MEMORY_POISONING ? + NULL : + av_buffer_allocz); if (!pool->pools[0]) { ret = AVERROR(ENOMEM); goto fail; diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h index 164c2583b6..742334978d 100644 --- a/libavcodec/golomb.h +++ b/libavcodec/golomb.h @@ -402,6 +402,7 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, log = av_log2(buf); if (log > 31 - limit) { + av_assert2(log >= k); buf >>= log - k; buf += (30U - log) << k; LAST_SKIP_BITS(re, gb, 32 + k - log); @@ -424,6 +425,8 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, /** * read unsigned golomb rice code (jpegls). + * + * @returns -1 on error */ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len) @@ -535,6 +538,8 @@ static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, /** * read signed golomb rice code (flac). + * + * @returns INT_MIN on error */ static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 910df7585f..c7b465d7ad 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -429,6 +429,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, MpegEncContext *s = avctx->priv_data; int ret; int slice_ret = 0; + int bak_width, bak_height; /* no supplementary picture */ if (buf_size == 0) { @@ -480,6 +481,9 @@ retry: if (ret < 0) return ret; + bak_width = s->width; + bak_height = s->height; + /* let's go :-) */ if (CONFIG_WMV2_DECODER && s->msmpeg4_version == 5) { ret = ff_wmv2_decode_picture_header(s); @@ -497,11 +501,12 @@ retry: } if (ret < 0 || ret == FRAME_SKIPPED) { - if ( s->width != avctx->coded_width - || s->height != avctx->coded_height) { + if ( s->width != bak_width + || s->height != bak_height) { av_log(s->avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n"); - s->width = avctx->coded_width; - s->height= avctx->coded_height; + s->width = bak_width; + s->height= bak_height; + } } if (ret == FRAME_SKIPPED) diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c index 9f66f079c2..b268f115db 100644 --- a/libavcodec/h2645_parse.c +++ b/libavcodec/h2645_parse.c @@ -579,9 +579,11 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, if (codec_id == AV_CODEC_ID_VVC) ret = vvc_parse_nal_header(nal, logctx); - else if (codec_id == AV_CODEC_ID_HEVC) + else if (codec_id == AV_CODEC_ID_HEVC) { ret = hevc_parse_nal_header(nal, logctx); - else + if (nal->nuh_layer_id == 63) + continue; + } else ret = h264_parse_nal_header(nal, logctx); if (ret < 0) { av_log(logctx, AV_LOG_WARNING, "Invalid NAL unit %d, skipping.\n", diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index afc103b69c..3b58d22d6f 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -621,8 +621,7 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, if (!sd) av_buffer_unref(&a53->buf_ref); a53->buf_ref = NULL; - if (avctx) - avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; + avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; } for (unsigned i = 0; i < sei->unregistered.nb_buf_ref; i++) { @@ -718,8 +717,7 @@ FF_ENABLE_DEPRECATION_WARNINGS else fgc->present = fgc->persistence_flag; - if (avctx) - avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; + avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; } #if CONFIG_HEVC_SEI diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index e9a404e41b..752735cc54 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1396,7 +1396,7 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl, sps = h->ps.sps; - if (sps && sps->bitstream_restriction_flag && + if (sps->bitstream_restriction_flag && h->avctx->has_b_frames < sps->num_reorder_frames) { h->avctx->has_b_frames = sps->num_reorder_frames; } diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c index 6066cb814c..805180b36e 100644 --- a/libavcodec/hapdec.c +++ b/libavcodec/hapdec.c @@ -309,6 +309,7 @@ static int hap_decode(AVCodecContext *avctx, AVFrame *frame, ret = av_reallocp(&ctx->tex_buf, ctx->tex_size); if (ret < 0) return ret; + memset(ctx->tex_buf, 0, ctx->tex_size); avctx->execute2(avctx, decompress_chunks_thread, NULL, ctx->chunk_results, ctx->chunk_count); diff --git a/libavcodec/hdrenc.c b/libavcodec/hdrenc.c index 40d283ee61..54682d0a77 100644 --- a/libavcodec/hdrenc.c +++ b/libavcodec/hdrenc.c @@ -124,7 +124,7 @@ static int hdr_encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t *buf; int ret; - packet_size = avctx->width * avctx->height * 4LL + 1024LL; + packet_size = avctx->height * 4LL + avctx->width * avctx->height * 8LL + 1024LL; if ((ret = ff_get_encode_buffer(avctx, pkt, packet_size, 0)) < 0) return ret; diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c index 99a4272fad..3f4702001e 100644 --- a/libavcodec/hevc_parser.c +++ b/libavcodec/hevc_parser.c @@ -105,7 +105,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, den = ps->sps->vui.vui_time_scale; } - if (num != 0 && den != 0) + if (num > 0 && den > 0) av_reduce(&avctx->framerate.den, &avctx->framerate.num, num, den, 1 << 30); diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index cbef3ef4cd..6475d86d7d 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -449,6 +449,15 @@ static void uninit_vps(FFRefStructOpaque opaque, void *obj) av_freep(&vps->hdr); } +static int compare_vps(const HEVCVPS *vps1, const HEVCVPS *vps2) +{ + if (!memcmp(vps1, vps2, offsetof(HEVCVPS, hdr))) + return !vps1->vps_num_hrd_parameters || + !memcmp(vps1->hdr, vps2->hdr, vps1->vps_num_hrd_parameters * sizeof(*vps1->hdr)); + + return 0; +} + int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps) { @@ -545,9 +554,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, goto err; } - vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); - if (!vps->hdr) - goto err; + if (vps->vps_num_hrd_parameters) { + vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); + if (!vps->hdr) + goto err; + } for (i = 0; i < vps->vps_num_hrd_parameters; i++) { int common_inf_present = 1; @@ -569,7 +580,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, } if (ps->vps_list[vps_id] && - !memcmp(ps->vps_list[vps_id], vps, sizeof(*vps))) { + compare_vps(ps->vps_list[vps_id], vps)) { ff_refstruct_unref(&vps); } else { remove_vps(ps, vps_id); diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h index cc75aeb8d3..0d8eaf2b3e 100644 --- a/libavcodec/hevc_ps.h +++ b/libavcodec/hevc_ps.h @@ -153,7 +153,6 @@ typedef struct PTL { typedef struct HEVCVPS { unsigned int vps_id; - HEVCHdrParams *hdr; uint8_t vps_temporal_id_nesting_flag; int vps_max_layers; @@ -175,6 +174,9 @@ typedef struct HEVCVPS { uint8_t data[4096]; int data_size; + /* Put this at the end of the structure to make it easier to calculate the + * size before this pointer, which is used for memcmp */ + HEVCHdrParams *hdr; } HEVCVPS; typedef struct ScalingList { diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 575836e340..9b3f31c948 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -371,7 +371,7 @@ static void export_stream_params(HEVCContext *s, const HEVCSPS *sps) den = sps->vui.vui_time_scale; } - if (num != 0 && den != 0) + if (num > 0 && den > 0) av_reduce(&avctx->framerate.den, &avctx->framerate.num, num, den, 1 << 30); } @@ -658,6 +658,10 @@ static int hls_slice_header(HEVCContext *s) if (s->ps.pps->dependent_slice_segments_enabled_flag) sh->dependent_slice_segment_flag = get_bits1(gb); + if (sh->dependent_slice_segment_flag && !s->slice_initialized) { + av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); + return AVERROR_INVALIDDATA; + } slice_address_length = av_ceil_log2(s->ps.sps->ctb_width * s->ps.sps->ctb_height); @@ -946,9 +950,6 @@ static int hls_slice_header(HEVCContext *s) } else { sh->slice_loop_filter_across_slices_enabled_flag = s->ps.pps->seq_loop_filter_across_slices_enabled_flag; } - } else if (!s->slice_initialized) { - av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); - return AVERROR_INVALIDDATA; } sh->num_entry_point_offsets = 0; @@ -1968,13 +1969,13 @@ static void hls_prediction_unit(HEVCLocalContext *lc, int x0, int y0, if (current_mv.pred_flag & PF_L0) { ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; - if (!ref0 || !ref0->frame->data[0]) + if (!ref0 || !ref0->frame) return; hevc_await_progress(s, ref0, ¤t_mv.mv[0], y0, nPbH); } if (current_mv.pred_flag & PF_L1) { ref1 = refPicList[1].ref[current_mv.ref_idx[1]]; - if (!ref1 || !ref1->frame->data[0]) + if (!ref1 || !ref1->frame) return; hevc_await_progress(s, ref1, ¤t_mv.mv[1], y0, nPbH); } @@ -2634,6 +2635,11 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist, if (ret < 0) goto error; hls_sao_param(lc, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size); + + s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; + s->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; + s->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; + more_data = hls_coding_quadtree(lc, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0); if (more_data < 0) { @@ -2892,10 +2898,15 @@ static int hevc_frame_start(HEVCContext *s) !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && !s->avctx->hwaccel; + ret = set_side_data(s); + if (ret < 0) + goto fail; + if (s->ref->needs_fg && - s->sei.common.film_grain_characteristics.present && - !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics.model_id, - s->ref->frame->format)) { + (s->sei.common.film_grain_characteristics.present && + !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics.model_id, + s->ref->frame->format) + || !av_film_grain_params_select(s->ref->frame))) { av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown, "Unsupported film grain parameters. Ignoring film grain.\n"); s->ref->needs_fg = 0; @@ -2909,10 +2920,6 @@ static int hevc_frame_start(HEVCContext *s) goto fail; } - ret = set_side_data(s); - if (ret < 0) - goto fail; - s->frame->pict_type = 3 - s->sh.slice_type; if (!IS_IRAP(s)) @@ -3036,8 +3043,11 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) case HEVC_NAL_RASL_N: case HEVC_NAL_RASL_R: ret = hls_slice_header(s); - if (ret < 0) + if (ret < 0) { + // hls_slice_header() does not cleanup on failure thus the state now is inconsistant so we cannot use it on depandant slices + s->slice_initialized = 0; return ret; + } if (ret == 1) { ret = AVERROR_INVALIDDATA; goto fail; diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c index ce6d4d4c59..b77f3808a6 100644 --- a/libavcodec/huffyuvdec.c +++ b/libavcodec/huffyuvdec.c @@ -773,6 +773,8 @@ static void decode_gray_bitstream(HYuvDecContext *s, int count) for (i = 0; i < count && BITS_LEFT(re, &s->gb) > 0; i++) { READ_2PIX(s->temp[0][2 * i], s->temp[0][2 * i + 1], 0); } + for (; i < count; i++) + s->temp[0][2 * i] = s->temp[0][2 * i + 1] = 0; } else { for (i = 0; i < count; i++) { READ_2PIX(s->temp[0][2 * i], s->temp[0][2 * i + 1], 0); diff --git a/libavcodec/iff.c b/libavcodec/iff.c index faf4e21c42..32d771b887 100644 --- a/libavcodec/iff.c +++ b/libavcodec/iff.c @@ -522,7 +522,7 @@ static int decode_byterun2(uint8_t *dst, int height, int line_size, GetByteContext *gb) { GetByteContext cmds; - unsigned count; + int count; int i, y_pos = 0, x_pos = 0; if (bytestream2_get_be32(gb) != MKBETAG('V', 'D', 'A', 'T')) @@ -530,7 +530,7 @@ static int decode_byterun2(uint8_t *dst, int height, int line_size, bytestream2_skip(gb, 4); count = bytestream2_get_be16(gb) - 2; - if (bytestream2_get_bytes_left(gb) < count) + if (count < 0 || bytestream2_get_bytes_left(gb) < count) return 0; bytestream2_init(&cmds, gb->buffer, count); diff --git a/libavcodec/ilbcdec.c b/libavcodec/ilbcdec.c index 4ecdff4183..7fea39b43c 100644 --- a/libavcodec/ilbcdec.c +++ b/libavcodec/ilbcdec.c @@ -658,7 +658,7 @@ static void get_codebook(int16_t * cbvec, /* (o) Constructed codebook vector * int16_t k, base_size; int16_t lag; /* Stack based */ - int16_t tempbuff2[SUBL + 5]; + int16_t tempbuff2[SUBL + 5] = {0}; /* Determine size of codebook sections */ base_size = lMem - cbveclen + 1; @@ -1095,12 +1095,6 @@ static void do_plc(int16_t *plc_residual, /* (o) concealed residual */ if (s->consPLICount * s->block_samples > 320) { use_gain = 29491; /* 0.9 in Q15 */ - } else if (s->consPLICount * s->block_samples > 640) { - use_gain = 22938; /* 0.7 in Q15 */ - } else if (s->consPLICount * s->block_samples > 960) { - use_gain = 16384; /* 0.5 in Q15 */ - } else if (s->consPLICount * s->block_samples > 1280) { - use_gain = 0; /* 0.0 in Q15 */ } /* Compute mixing factor of picth repeatition and noise: diff --git a/libavcodec/imm4.c b/libavcodec/imm4.c index 656fc9c05f..0b74068b03 100644 --- a/libavcodec/imm4.c +++ b/libavcodec/imm4.c @@ -219,12 +219,15 @@ static int decode_intra(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame for (y = 0; y < avctx->height; y += 16) { for (x = 0; x < avctx->width; x += 16) { - unsigned flag, cbphi, cbplo; + unsigned flag, cbplo; + int cbphi; cbplo = get_vlc2(gb, cbplo_tab, CBPLO_VLC_BITS, 1); flag = get_bits1(gb); cbphi = get_cbphi(gb, 1); + if (cbphi < 0) + return cbphi; ret = decode_blocks(avctx, gb, cbplo | (cbphi << 2), 0, offset, flag); if (ret < 0) @@ -272,7 +275,8 @@ static int decode_inter(AVCodecContext *avctx, GetBitContext *gb, for (y = 0; y < avctx->height; y += 16) { for (x = 0; x < avctx->width; x += 16) { int reverse, intra_block, value; - unsigned cbphi, cbplo, flag2 = 0; + unsigned cbplo, flag2 = 0; + int cbphi; if (get_bits1(gb)) { copy_block16(frame->data[0] + y * frame->linesize[0] + x, @@ -298,6 +302,9 @@ static int decode_inter(AVCodecContext *avctx, GetBitContext *gb, cbplo = value >> 4; cbphi = get_cbphi(gb, reverse); + if (cbphi < 0) + return cbphi; + if (intra_block) { ret = decode_blocks(avctx, gb, cbplo | (cbphi << 2), 0, offset, flag2); if (ret < 0) @@ -445,6 +452,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame, if (ret < 0) return ret; + if (((avctx->width + 15) / 16) * ((avctx->height + 15) / 16) > get_bits_left(gb)) + return AVERROR_INVALIDDATA; + + if ((ret = ff_get_buffer(avctx, frame, (frame->flags & AV_FRAME_FLAG_KEY) ? AV_GET_BUFFER_FLAG_REF : 0)) < 0) return ret; diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c index a80e74d4ec..6f827be05b 100644 --- a/libavcodec/j2kenc.c +++ b/libavcodec/j2kenc.c @@ -1348,7 +1348,7 @@ static void makelayers(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile) } } -static int getcut(Jpeg2000Cblk *cblk, uint64_t lambda, int dwt_norm) +static int getcut(Jpeg2000Cblk *cblk, uint64_t lambda) { int passno, res = 0; for (passno = 0; passno < cblk->npasses; passno++){ @@ -1360,7 +1360,7 @@ static int getcut(Jpeg2000Cblk *cblk, uint64_t lambda, int dwt_norm) dd = cblk->passes[passno].disto - (res ? cblk->passes[res-1].disto : 0); - if (((dd * dwt_norm) >> WMSEDEC_SHIFT) * dwt_norm >= dr * lambda) + if (dd >= dr * lambda) res = passno+1; } return res; @@ -1383,11 +1383,12 @@ static void truncpasses(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile) Jpeg2000Band *band = reslevel->band + bandno; Jpeg2000Prec *prec = band->prec + precno; + int64_t dwt_norm = dwt_norms[codsty->transform == FF_DWT53][bandpos][lev] * (int64_t)band->i_stepsize >> 15; + int64_t lambda_prime = av_rescale(s->lambda, 1 << WMSEDEC_SHIFT, dwt_norm * dwt_norm); for (cblkno = 0; cblkno < prec->nb_codeblocks_height * prec->nb_codeblocks_width; cblkno++){ Jpeg2000Cblk *cblk = prec->cblk + cblkno; - cblk->ninclpasses = getcut(cblk, s->lambda, - (int64_t)dwt_norms[codsty->transform == FF_DWT53][bandpos][lev] * (int64_t)band->i_stepsize >> 15); + cblk->ninclpasses = getcut(cblk, lambda_prime); cblk->layers[0].data_start = cblk->data; cblk->layers[0].cum_passes = cblk->ninclpasses; cblk->layers[0].npasses = cblk->ninclpasses; diff --git a/libavcodec/jfdctint_template.c b/libavcodec/jfdctint_template.c index ca17300c32..58827b677e 100644 --- a/libavcodec/jfdctint_template.c +++ b/libavcodec/jfdctint_template.c @@ -69,7 +69,7 @@ #define GLOBAL(x) x #define RIGHT_SHIFT(x, n) ((x) >> (n)) #define MULTIPLY16C16(var,const) ((var)*(const)) -#define DESCALE(x,n) RIGHT_SHIFT((x) + (1 << ((n) - 1)), n) +#define DESCALE(x,n) RIGHT_SHIFT((int)(x) + (1 << ((n) - 1)), n) /* @@ -175,7 +175,7 @@ #if BITS_IN_JSAMPLE == 8 && CONST_BITS<=13 && PASS1_BITS<=2 #define MULTIPLY(var,const) MULTIPLY16C16(var,const) #else -#define MULTIPLY(var,const) ((var) * (const)) +#define MULTIPLY(var,const) (int)((var) * (unsigned)(const)) #endif @@ -183,7 +183,7 @@ static av_always_inline void FUNC(row_fdct)(int16_t *data) { int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int tmp10, tmp11, tmp12, tmp13; - int z1, z2, z3, z4, z5; + unsigned z1, z2, z3, z4, z5; int16_t *dataptr; int ctr; @@ -261,7 +261,7 @@ FUNC(ff_jpeg_fdct_islow)(int16_t *data) { int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int tmp10, tmp11, tmp12, tmp13; - int z1, z2, z3, z4, z5; + unsigned z1, z2, z3, z4, z5; int16_t *dataptr; int ctr; diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 1afc6b1e2d..72aaefbdb3 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -834,9 +834,6 @@ static int get_tlm(Jpeg2000DecoderContext *s, int n) case 2: bytestream2_get_be16(&s->g); break; - case 3: - bytestream2_get_be32(&s->g); - break; } if (SP == 0) { bytestream2_get_be16(&s->g); @@ -1885,7 +1882,7 @@ static inline void roi_scale_cblk(Jpeg2000Cblk *cblk, } } -static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile *tile) +static inline int tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile *tile) { Jpeg2000T1Context t1; @@ -1910,6 +1907,8 @@ static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile int nb_precincts, precno; Jpeg2000Band *band = rlevel->band + bandno; int cblkno = 0, bandpos; + /* See Rec. ITU-T T.800, Equation E-2 */ + int magp = quantsty->expn[subbandno] + quantsty->nguardbits - 1; bandpos = bandno + (reslevelno > 0); @@ -1917,6 +1916,11 @@ static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile band->coord[1][0] == band->coord[1][1]) continue; + if ((codsty->cblk_style & JPEG2000_CTSY_HTJ2K_F) && magp >= 31) { + avpriv_request_sample(s->avctx, "JPEG2000_CTSY_HTJ2K_F and magp >= 31"); + return AVERROR_PATCHWELCOME; + } + nb_precincts = rlevel->num_precincts_x * rlevel->num_precincts_y; /* Loop on precincts */ for (precno = 0; precno < nb_precincts; precno++) { @@ -1927,8 +1931,6 @@ static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height; cblkno++) { int x, y, ret; - /* See Rec. ITU-T T.800, Equation E-2 */ - int magp = quantsty->expn[subbandno] + quantsty->nguardbits - 1; Jpeg2000Cblk *cblk = prec->cblk + cblkno; @@ -1968,6 +1970,7 @@ static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile ff_dwt_decode(&comp->dwt, codsty->transform == FF_DWT97 ? (void*)comp->f_data : (void*)comp->i_data); } /*end comp */ + return 0; } #define WRITE_FRAME(D, PIXEL) \ @@ -2044,7 +2047,9 @@ static int jpeg2000_decode_tile(AVCodecContext *avctx, void *td, AVFrame *picture = td; Jpeg2000Tile *tile = s->tile + jobnr; - tile_codeblocks(s, tile); + int ret = tile_codeblocks(s, tile); + if (ret < 0) + return ret; /* inverse MCT transformation */ if (tile->codsty[0].mct) diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c index 6b9898d3ff..4f0b10b429 100644 --- a/libavcodec/jpeg2000htdec.c +++ b/libavcodec/jpeg2000htdec.c @@ -1198,6 +1198,9 @@ ff_jpeg2000_decode_htj2k(const Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c av_assert0(width * height <= 4096); av_assert0(width * height > 0); + if (roi_shift) + avpriv_report_missing_feature(s->avctx, "ROI shift"); + memset(t1->data, 0, t1->stride * height * sizeof(*t1->data)); memset(t1->flags, 0, t1->stride * (height + 2) * sizeof(*t1->flags)); diff --git a/libavcodec/jpegxl_parser.c b/libavcodec/jpegxl_parser.c index 8c45e1a1b7..76122af54a 100644 --- a/libavcodec/jpegxl_parser.c +++ b/libavcodec/jpegxl_parser.c @@ -352,6 +352,8 @@ static int decode_hybrid_varlen_uint(GetBitContext *gb, JXLEntropyDecoder *dec, if (bundle->lz77_enabled && token >= bundle->lz77_min_symbol) { const JXLSymbolDistribution *lz77dist = &bundle->dists[bundle->cluster_map[bundle->num_dist - 1]]; + if (!dec->num_decoded) + return AVERROR_INVALIDDATA; ret = read_hybrid_uint(gb, &bundle->lz_len_conf, token - bundle->lz77_min_symbol, &dec->num_to_copy); if (ret < 0) return ret; @@ -531,6 +533,7 @@ static int read_dist_clustering(GetBitContext *gb, JXLEntropyDecoder *dec, JXLDi dec->state = -1; /* it's not going to necessarily be zero after reading */ dec->num_to_copy = 0; + dec->num_decoded = 0; dist_bundle_close(&nested); if (use_mtf) { uint8_t mtf[256]; @@ -1311,7 +1314,7 @@ static int parse_frame_header(void *avctx, JXLParseContext *ctx, GetBitContext * // permuted toc if (get_bits1(gb)) { JXLEntropyDecoder dec; - uint32_t end, lehmer = 0; + int64_t end, lehmer = 0; ret = entropy_decoder_init(avctx, gb, &dec, 8); if (ret < 0) return ret; @@ -1320,13 +1323,13 @@ static int parse_frame_header(void *avctx, JXLParseContext *ctx, GetBitContext * return AVERROR_BUFFER_TOO_SMALL; } end = entropy_decoder_read_symbol(gb, &dec, toc_context(toc_count)); - if (end > toc_count) { + if (end < 0 || end > toc_count) { entropy_decoder_close(&dec); return AVERROR_INVALIDDATA; } for (uint32_t i = 0; i < end; i++) { lehmer = entropy_decoder_read_symbol(gb, &dec, toc_context(lehmer)); - if (get_bits_left(gb) < 0) { + if (lehmer < 0 || get_bits_left(gb) < 0) { entropy_decoder_close(&dec); return AVERROR_BUFFER_TOO_SMALL; } diff --git a/libavcodec/leaddec.c b/libavcodec/leaddec.c index f7d31681b8..a6f6c3cc87 100644 --- a/libavcodec/leaddec.c +++ b/libavcodec/leaddec.c @@ -196,7 +196,9 @@ static int lead_decode_frame(AVCodecContext *avctx, AVFrame * frame, i++; } - init_get_bits8(&gb, s->bitstream_buf, size); + ret = init_get_bits8(&gb, s->bitstream_buf, size); + if (ret < 0) + return ret; if (avctx->pix_fmt == AV_PIX_FMT_YUV420P && zero) { for (int mb_y = 0; mb_y < avctx->height / 8; mb_y++) diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 4b89e47e83..b1aa1c85ad 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -2040,6 +2040,7 @@ const FFCodec ff_libvpx_vp8_encoder = { FF_CODEC_ENCODE_CB(vpx_encode), .close = vpx_free, .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | + FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS, .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE }, .p.priv_class = &class_vp8, @@ -2116,6 +2117,7 @@ FFCodec ff_libvpx_vp9_encoder = { FF_CODEC_ENCODE_CB(vpx_encode), .close = vpx_free, .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | + FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS, .defaults = defaults, .init_static_data = vp9_init_static, diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index eadb20d2b3..813ccbbdb3 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -929,7 +929,9 @@ static int set_avcc_extradata(AVCodecContext *avctx, x264_nal_t *nal, int nnal) * * +4 to skip until sps id. */ - init_get_bits8(&gbc, sps + 4, sps_nal->i_payload - 4 - 4); + ret = init_get_bits8(&gbc, sps + 4, sps_nal->i_payload - 4 - 4); + if (ret < 0) + return ret; // Skip sps id get_ue_golomb_31(&gbc); chroma_format_idc = get_ue_golomb_31(&gbc); diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index d3e74eaacf..0107310068 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -646,7 +646,13 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, { libx265Context *ctx = avctx->priv_data; x265_picture x265pic; - x265_picture x265pic_out = { 0 }; +#if (X265_BUILD >= 210) && (X265_BUILD < 213) + x265_picture x265pic_layers_out[MAX_SCALABLE_LAYERS]; + x265_picture* x265pic_lyrptr_out[MAX_SCALABLE_LAYERS]; +#else + x265_picture x265pic_solo_out = { 0 }; +#endif + x265_picture* x265pic_out; x265_nal *nal; x265_sei *sei; uint8_t *dst; @@ -764,8 +770,16 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, } } +#if (X265_BUILD >= 210) && (X265_BUILD < 213) + for (i = 0; i < MAX_SCALABLE_LAYERS; i++) + x265pic_lyrptr_out[i] = &x265pic_layers_out[i]; + ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal, - pic ? &x265pic : NULL, &x265pic_out); + pic ? &x265pic : NULL, x265pic_lyrptr_out); +#else + ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal, + pic ? &x265pic : NULL, &x265pic_solo_out); +#endif for (i = 0; i < sei->numPayloads; i++) av_free(sei->payloads[i].payload); @@ -795,10 +809,16 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, pkt->flags |= AV_PKT_FLAG_KEY; } - pkt->pts = x265pic_out.pts; - pkt->dts = x265pic_out.dts; +#if (X265_BUILD >= 210) && (X265_BUILD < 213) + x265pic_out = x265pic_lyrptr_out[0]; +#else + x265pic_out = &x265pic_solo_out; +#endif - switch (x265pic_out.sliceType) { + pkt->pts = x265pic_out->pts; + pkt->dts = x265pic_out->dts; + + switch (x265pic_out->sliceType) { case X265_TYPE_IDR: case X265_TYPE_I: pict_type = AV_PICTURE_TYPE_I; @@ -816,16 +836,16 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, } #if X265_BUILD >= 130 - if (x265pic_out.sliceType == X265_TYPE_B) + if (x265pic_out->sliceType == X265_TYPE_B) #else - if (x265pic_out.frameData.sliceType == 'b') + if (x265pic_out->frameData.sliceType == 'b') #endif pkt->flags |= AV_PKT_FLAG_DISPOSABLE; - ff_side_data_set_encoder_stats(pkt, x265pic_out.frameData.qp * FF_QP2LAMBDA, NULL, 0, pict_type); + ff_side_data_set_encoder_stats(pkt, x265pic_out->frameData.qp * FF_QP2LAMBDA, NULL, 0, pict_type); - if (x265pic_out.userData) { - int idx = (int)(intptr_t)x265pic_out.userData - 1; + if (x265pic_out->userData) { + int idx = (int)(intptr_t)x265pic_out->userData - 1; ReorderedData *rd = &ctx->rd[idx]; pkt->duration = rd->duration; diff --git a/libavcodec/loco.c b/libavcodec/loco.c index 3d11823284..8cc270acbb 100644 --- a/libavcodec/loco.c +++ b/libavcodec/loco.c @@ -92,10 +92,15 @@ static inline int loco_get_rice(RICEContext *r) if (get_bits_left(&r->gb) < 1) return INT_MIN; v = get_ur_golomb_jpegls(&r->gb, loco_get_rice_param(r), INT_MAX, 0); + if (v == -1) + return INT_MIN; loco_update_rice_param(r, (v + 1) >> 1); if (!v) { if (r->save >= 0) { - r->run = get_ur_golomb_jpegls(&r->gb, 2, INT_MAX, 0); + int run = get_ur_golomb_jpegls(&r->gb, 2, INT_MAX, 0); + if (run == -1) + return INT_MIN; + r->run = run; if (r->run > 1) r->save += r->run + 1; else @@ -152,6 +157,8 @@ static int loco_decode_plane(LOCOContext *l, uint8_t *data, int width, int heigh /* restore top left pixel */ val = loco_get_rice(&rc); + if (val == INT_MIN) + return AVERROR_INVALIDDATA; data[0] = 128 + val; /* restore top line */ for (i = 1; i < width; i++) { diff --git a/libavcodec/lossless_videoencdsp.c b/libavcodec/lossless_videoencdsp.c index 8d03a5b5c6..0a3a4ec509 100644 --- a/libavcodec/lossless_videoencdsp.c +++ b/libavcodec/lossless_videoencdsp.c @@ -25,13 +25,11 @@ #if HAVE_FAST_64BIT typedef uint64_t uint_native; #define READ AV_RN64 -#define READA AV_RN64A -#define WRITEA AV_WN64A +#define WRITE AV_WN64 #else typedef uint32_t uint_native; #define READ AV_RN32 -#define READA AV_RN32A -#define WRITEA AV_WN32A +#define WRITE AV_WN32 #endif // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size #define pb_7f (~(uint_native)0 / 255 * 0x7f) @@ -56,9 +54,9 @@ static void diff_bytes_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, } else #endif for (i = 0; i <= w - (int) sizeof(uint_native); i += sizeof(uint_native)) { - uint_native a = READA(src1 + i); + uint_native a = READ(src1 + i); uint_native b = READ(src2 + i); - WRITEA(dst + i, ((a | pb_80) - (b & pb_7f)) ^ ((a ^ b ^ pb_80) & pb_80)); + WRITE(dst + i, ((a | pb_80) - (b & pb_7f)) ^ ((a ^ b ^ pb_80) & pb_80)); } for (; i < w; i++) dst[i + 0] = src1[i + 0] - src2[i + 0]; diff --git a/libavcodec/lossless_videoencdsp.h b/libavcodec/lossless_videoencdsp.h index 07fff584af..7fd0ad32c7 100644 --- a/libavcodec/lossless_videoencdsp.h +++ b/libavcodec/lossless_videoencdsp.h @@ -23,8 +23,8 @@ #include typedef struct LLVidEncDSPContext { - void (*diff_bytes)(uint8_t *dst /* align 16 */, - const uint8_t *src1 /* align 16 */, + void (*diff_bytes)(uint8_t *dst /* align 1 */, + const uint8_t *src1 /* align 1 */, const uint8_t *src2 /* align 1 */, intptr_t w); /** diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c index 53f5c3d379..88ab37e761 100644 --- a/libavcodec/lpc.c +++ b/libavcodec/lpc.c @@ -281,8 +281,10 @@ int ff_lpc_calc_coefs(LPCContext *s, double av_uninit(weight); memset(var, 0, FFALIGN(MAX_LPC_ORDER+1,4)*sizeof(*var)); - for(j=0; j 1) + for(j=0; j 0;) {\ ret = get_vlc_multi(&gb, (uint8_t *)dst + x * b, multi, \ - vlc, vlc_bits, 3); \ + vlc, vlc_bits, 3, b); \ if (ret <= 0) \ return AVERROR_INVALIDDATA; \ x += ret; \ diff --git a/libavcodec/magicyuvenc.c b/libavcodec/magicyuvenc.c index 1c3ab56460..e8e03d2461 100644 --- a/libavcodec/magicyuvenc.c +++ b/libavcodec/magicyuvenc.c @@ -375,11 +375,14 @@ static int count_plane_slice(AVCodecContext *avctx, int n, int plane) Slice *sl = &s->slices[n * s->planes + plane]; const uint8_t *dst = sl->slice; PTable *counts = sl->counts; + const int slice_height = s->slice_height; + const int last_height = FFMIN(slice_height, avctx->height - n * slice_height); + const int height = (n < (s->nb_slices - 1)) ? slice_height : last_height; memset(counts, 0, sizeof(sl->counts)); count_usage(dst, AV_CEIL_RSHIFT(avctx->width, s->hshift[plane]), - AV_CEIL_RSHIFT(s->slice_height, s->vshift[plane]), counts); + AV_CEIL_RSHIFT(height, s->vshift[plane]), counts); return 0; } diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c index 984014f1b1..d3bf27cb7f 100644 --- a/libavcodec/mediacodecenc.c +++ b/libavcodec/mediacodecenc.c @@ -200,9 +200,19 @@ static av_cold int mediacodec_init(AVCodecContext *avctx) ff_AMediaFormat_setString(format, "mime", codec_mime); // Workaround the alignment requirement of mediacodec. We can't do it // silently for AV_PIX_FMT_MEDIACODEC. - if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC) { + if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC && + (avctx->codec_id == AV_CODEC_ID_H264 || + avctx->codec_id == AV_CODEC_ID_HEVC)) { s->width = FFALIGN(avctx->width, 16); s->height = FFALIGN(avctx->height, 16); + // If avctx video size is aligned to 16 already, we don't need to do + // anything. If align is needed for HEVC, we should use the maximum CTU + // size. + if (avctx->codec_id == AV_CODEC_ID_HEVC && + (s->width != avctx->width || s->height != avctx->height)) { + s->width = FFALIGN(avctx->width, 64); + s->height = FFALIGN(avctx->height, 64); + } } else { s->width = avctx->width; s->height = avctx->height; @@ -533,7 +543,7 @@ static int mediacodec_encode(AVCodecContext *avctx, AVPacket *pkt) return 0; } - if (ret != AVERROR(EAGAIN)) + if (ret < 0 && ret != AVERROR(EAGAIN)) return ret; if (!s->frame->buf[0]) { diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c index 9225692c51..a674a35aa4 100644 --- a/libavcodec/mfenc.c +++ b/libavcodec/mfenc.c @@ -248,7 +248,7 @@ static int mf_sample_to_avpacket(AVCodecContext *avctx, IMFSample *sample, AVPac if ((ret = ff_get_encode_buffer(avctx, avpkt, len, 0)) < 0) return ret; - IMFSample_ConvertToContiguousBuffer(sample, &buffer); + hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer); if (FAILED(hr)) return AVERROR_EXTERNAL; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index c9409eac6c..9085c04a9b 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -467,6 +467,10 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) if (s->avctx->height <= 0) return AVERROR_INVALIDDATA; } + if (s->bayer && s->progressive) { + avpriv_request_sample(s->avctx, "progressively coded bayer picture"); + return AVERROR_INVALIDDATA; + } if (s->got_picture && s->interlaced && (s->bottom_field == !s->interlace_polarity)) { if (s->progressive) { diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index 67e0e109aa..06670de456 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -1414,7 +1414,8 @@ static int estimate_coeff(MLPEncodeContext *ctx, MLPSubstream *s, int32_t maxl = INT32_MIN, maxr = INT32_MIN, minl = INT32_MAX, minr = INT32_MAX; int64_t summ = 0, sums = 0, suml = 0, sumr = 0, enl = 0, enr = 0; const int shift = 14 - ctx->rematrix_precision; - int32_t cf0, cf1, e[4], d[4], ml, mr; + int32_t cf0, cf1, e[4], d[4]; + int64_t ml, mr; int i, count = 0; for (int j = 0; j <= ctx->cur_restart_interval; j++) { @@ -1447,8 +1448,8 @@ static int estimate_coeff(MLPEncodeContext *ctx, MLPSubstream *s, summ -= FFABS(suml + sumr); sums -= FFABS(suml - sumr); - ml = maxl - minl; - mr = maxr - minr; + ml = maxl - (int64_t)minl; + mr = maxr - (int64_t)minr; if (!summ && !sums) return 0; diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index df9d1befa8..2091acbbec 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -1446,7 +1446,7 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y) s->b_direct_mv_table[mot_xy][0]= 0; s->b_direct_mv_table[mot_xy][1]= 0; - return 256*256*256*64; + return 256*256*256*64-1; } c->xmin= xmin; diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 4ad1eb6572..d05d6355e0 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2733,7 +2733,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame, int ret; // Check for minimal intra MB size (considering mb header, luma & chroma dc VLC, ac EOB VLC) - if (avpkt->size*8LL < (avctx->width+15)/16 * ((avctx->height+15)/16) * (2 + 3*4 + 2*2 + 2*6)) + if (avpkt->size*8LL < (avctx->width+15)/16 * ((avctx->height+15)/16) * (2LL + 3*4 + 2*2 + 2*6)) return AVERROR_INVALIDDATA; ret = ff_get_buffer(avctx, frame, 0); diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index f956dde78f..76377aea1b 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -333,7 +333,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s) else /* VBV calculation: Scaled so that a VCD has the proper * VBV size of 40 kilobytes */ - vbv_buffer_size = ((20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024; + vbv_buffer_size = av_rescale_rnd(s->bit_rate, 20, 1151929 / 2, AV_ROUND_ZERO) * 8 * 1024; vbv_buffer_size = (vbv_buffer_size + 16383) / 16384; put_sbits(&s->pb, 18, v); diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index 07de5d6d91..04a9ae504e 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -597,6 +597,8 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g ctx->sprite_shift[0] = alpha + beta + rho - min_ab; ctx->sprite_shift[1] = alpha + beta + rho - min_ab + 2; break; + default: + av_assert0(0); } /* try to simplify the situation */ if (sprite_delta[0][0] == a << ctx->sprite_shift[0] && diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index c20e364cac..c1228f21e5 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -526,6 +526,12 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "H.263 does not support resolutions above 2048x1152\n"); return AVERROR(EINVAL); } + if (s->codec_id == AV_CODEC_ID_FLV1 && + (avctx->width > 65535 || + avctx->height > 65535 )) { + av_log(avctx, AV_LOG_ERROR, "FLV does not support resolutions above 16bit\n"); + return AVERROR(EINVAL); + } if ((s->codec_id == AV_CODEC_ID_H263 || s->codec_id == AV_CODEC_ID_H263P || s->codec_id == AV_CODEC_ID_RV20) && @@ -1198,8 +1204,8 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) ptrdiff_t dst_stride = i ? s->uvlinesize : s->linesize; int h_shift = i ? s->chroma_x_shift : 0; int v_shift = i ? s->chroma_y_shift : 0; - int w = s->width >> h_shift; - int h = s->height >> v_shift; + int w = AV_CEIL_RSHIFT(s->width , h_shift); + int h = AV_CEIL_RSHIFT(s->height, v_shift); const uint8_t *src = pic_arg->data[i]; uint8_t *dst = pic->f->data[i]; int vpad = 16; @@ -1252,6 +1258,8 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) /* shift buffer entries */ for (int i = flush_offset; i <= MAX_B_FRAMES; i++) s->input_picture[i - flush_offset] = s->input_picture[i]; + for (int i = MAX_B_FRAMES + 1 - flush_offset; i <= MAX_B_FRAMES; i++) + s->input_picture[i] = NULL; s->input_picture[encoding_delay] = pic; @@ -1433,7 +1441,7 @@ static int estimate_best_b_count(MpegEncContext *s) goto fail; } - rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); + rd += (out_size * (uint64_t)lambda2) >> (FF_LAMBDA_SHIFT - 3); } /* get the delayed frames */ @@ -1442,7 +1450,7 @@ static int estimate_best_b_count(MpegEncContext *s) ret = out_size; goto fail; } - rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); + rd += (out_size * (uint64_t)lambda2) >> (FF_LAMBDA_SHIFT - 3); rd += c->error[0] + c->error[1] + c->error[2]; diff --git a/libavcodec/mscc.c b/libavcodec/mscc.c index d1d23e6751..e467b48baf 100644 --- a/libavcodec/mscc.c +++ b/libavcodec/mscc.c @@ -53,6 +53,9 @@ static int rle_uncompress(AVCodecContext *avctx, GetByteContext *gb, PutByteCont unsigned run = bytestream2_get_byte(gb); if (run) { + if (bytestream2_get_bytes_left_p(pb) < run * s->bpp) + return AVERROR_INVALIDDATA; + switch (avctx->bits_per_coded_sample) { case 8: fill = bytestream2_get_byte(gb); @@ -101,6 +104,9 @@ static int rle_uncompress(AVCodecContext *avctx, GetByteContext *gb, PutByteCont bytestream2_seek_p(pb, y * avctx->width * s->bpp + x * s->bpp, SEEK_SET); } else { + if (bytestream2_get_bytes_left_p(pb) < copy * s->bpp) + return AVERROR_INVALIDDATA; + for (j = 0; j < copy; j++) { switch (avctx->bits_per_coded_sample) { case 8: diff --git a/libavcodec/mvha.c b/libavcodec/mvha.c index 356cebc64e..87fe3c7100 100644 --- a/libavcodec/mvha.c +++ b/libavcodec/mvha.c @@ -183,6 +183,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame, av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", ret); return AVERROR_EXTERNAL; } + if (zstream->avail_out > 0) + memset(zstream->next_out, 0, zstream->avail_out); } } } else if (type == MKTAG('H','U','F','Y')) { diff --git a/libavcodec/mwsc.c b/libavcodec/mwsc.c index f8c53c33ff..a7e8702580 100644 --- a/libavcodec/mwsc.c +++ b/libavcodec/mwsc.c @@ -50,6 +50,10 @@ static int rle_uncompress(GetByteContext *gb, PutByteContext *pb, GetByteContext if (run == 0) { run = bytestream2_get_le32(gb); + + if (bytestream2_tell_p(pb) + width - w < run) + return AVERROR_INVALIDDATA; + for (int j = 0; j < run; j++, w++) { if (w == width) { w = 0; @@ -61,6 +65,10 @@ static int rle_uncompress(GetByteContext *gb, PutByteContext *pb, GetByteContext int pos = bytestream2_tell_p(pb); bytestream2_seek(gbp, pos, SEEK_SET); + + if (pos + width - w < fill) + return AVERROR_INVALIDDATA; + for (int j = 0; j < fill; j++, w++) { if (w == width) { w = 0; @@ -72,6 +80,9 @@ static int rle_uncompress(GetByteContext *gb, PutByteContext *pb, GetByteContext intra = 0; } else { + if (bytestream2_tell_p(pb) + width - w < run) + return AVERROR_INVALIDDATA; + for (int j = 0; j < run; j++, w++) { if (w == width) { w = 0; diff --git a/libavcodec/notchlc.c b/libavcodec/notchlc.c index 0feb0918f0..f8c104b33c 100644 --- a/libavcodec/notchlc.c +++ b/libavcodec/notchlc.c @@ -92,6 +92,9 @@ static int lz4_decompress(AVCodecContext *avctx, } while (current == 255); } + if (bytestream2_get_bytes_left(gb) < num_literals) + return AVERROR_INVALIDDATA; + if (pos + num_literals < HISTORY_SIZE) { bytestream2_get_buffer(gb, history + pos, num_literals); pos += num_literals; @@ -242,7 +245,9 @@ static int decode_blocks(AVCodecContext *avctx, AVFrame *p, bytestream2_seek(&dgb, s->y_data_offset + row_offset, SEEK_SET); - init_get_bits8(&bit, dgb.buffer, bytestream2_get_bytes_left(&dgb)); + ret = init_get_bits8(&bit, dgb.buffer, bytestream2_get_bytes_left(&dgb)); + if (ret < 0) + return ret; for (int x = 0; x < avctx->width; x += 4) { unsigned item = bytestream2_get_le32(gb); unsigned y_min = item & 4095; diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index 553c9bdf18..1741ee7e47 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -664,6 +664,8 @@ int ff_nvdec_simple_end_frame(AVCodecContext *avctx) NVDECContext *ctx = avctx->internal->hwaccel_priv_data; int ret = ff_nvdec_end_frame(avctx); ctx->bitstream = NULL; + ctx->bitstream_len = 0; + ctx->nb_slices = 0; return ret; } diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index fd73af2a32..a44beb349f 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -982,7 +982,7 @@ static av_cold int nvenc_recalc_surfaces(AVCodecContext *avctx) // Output in the worst case will only start when the surface buffer is completely full. // Hence we need to keep at least the max amount of surfaces plus the max reorder delay around. - ctx->frame_data_array_nb = ctx->nb_surfaces + ctx->encode_config.frameIntervalP - 1; + ctx->frame_data_array_nb = FFMAX(ctx->nb_surfaces, ctx->nb_surfaces + ctx->encode_config.frameIntervalP - 1); return 0; } @@ -1255,6 +1255,11 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx) h264->level = ctx->level; +#ifdef NVENC_HAVE_NEW_BIT_DEPTH_API + h264->inputBitDepth = h264->outputBitDepth = + IS_10BIT(ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8; +#endif + if (ctx->coder >= 0) h264->entropyCodingMode = ctx->coder; @@ -1370,7 +1375,12 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) hevc->chromaFormatIDC = IS_YUV444(ctx->data_pix_fmt) ? 3 : 1; +#ifdef NVENC_HAVE_NEW_BIT_DEPTH_API + hevc->inputBitDepth = hevc->outputBitDepth = + IS_10BIT(ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8; +#else hevc->pixelBitDepthMinus8 = IS_10BIT(ctx->data_pix_fmt) ? 2 : 0; +#endif hevc->level = ctx->level; @@ -1455,8 +1465,13 @@ static av_cold int nvenc_setup_av1_config(AVCodecContext *avctx) av1->chromaFormatIDC = IS_YUV444(ctx->data_pix_fmt) ? 3 : 1; +#ifdef NVENC_HAVE_NEW_BIT_DEPTH_API + av1->inputBitDepth = IS_10BIT(ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8; + av1->outputBitDepth = (IS_10BIT(ctx->data_pix_fmt) || ctx->highbitdepth) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8; +#else av1->inputPixelBitDepthMinus8 = IS_10BIT(ctx->data_pix_fmt) ? 2 : 0; av1->pixelBitDepthMinus8 = (IS_10BIT(ctx->data_pix_fmt) || ctx->highbitdepth) ? 2 : 0; +#endif if (ctx->b_ref_mode >= 0) av1->useBFramesAsRef = ctx->b_ref_mode; @@ -1689,15 +1704,15 @@ static NV_ENC_BUFFER_FORMAT nvenc_map_buffer_format(enum AVPixelFormat pix_fmt) { switch (pix_fmt) { case AV_PIX_FMT_YUV420P: - return NV_ENC_BUFFER_FORMAT_YV12_PL; + return NV_ENC_BUFFER_FORMAT_YV12; case AV_PIX_FMT_NV12: - return NV_ENC_BUFFER_FORMAT_NV12_PL; + return NV_ENC_BUFFER_FORMAT_NV12; case AV_PIX_FMT_P010: case AV_PIX_FMT_P016: return NV_ENC_BUFFER_FORMAT_YUV420_10BIT; case AV_PIX_FMT_GBRP: case AV_PIX_FMT_YUV444P: - return NV_ENC_BUFFER_FORMAT_YUV444_PL; + return NV_ENC_BUFFER_FORMAT_YUV444; case AV_PIX_FMT_GBRP16: case AV_PIX_FMT_YUV444P16: return NV_ENC_BUFFER_FORMAT_YUV444_10BIT; @@ -1876,7 +1891,7 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx) av_fifo_freep2(&ctx->unused_surface_queue); if (ctx->frame_data_array) { - for (i = 0; i < ctx->nb_surfaces; i++) + for (i = 0; i < ctx->frame_data_array_nb; i++) av_buffer_unref(&ctx->frame_data_array[i].frame_opaque_ref); av_freep(&ctx->frame_data_array); } diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index 48cdfc58aa..d99d8a0d76 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -83,6 +83,11 @@ typedef void ID3D11Device; #define NVENC_NO_DEPRECATED_RC #endif +// SDK 12.2 compile time feature checks +#if NVENCAPI_CHECK_VERSION(12, 2) +#define NVENC_HAVE_NEW_BIT_DEPTH_API +#endif + typedef struct NvencSurface { NV_ENC_INPUT_PTR input_surface; diff --git a/libavcodec/osq.c b/libavcodec/osq.c index 650cfcd98c..17dec52fcc 100644 --- a/libavcodec/osq.c +++ b/libavcodec/osq.c @@ -159,12 +159,18 @@ static int update_residue_parameter(OSQChannel *cb) int rice_k; sum = cb->sum; + if (!sum) + return 0; x = sum / cb->count; - rice_k = av_ceil_log2(x); + rice_k = ceil(log2(x)); if (rice_k >= 30) { - rice_k = floor(sum / 1.4426952 + 0.5); - if (rice_k < 1) + double f = floor(sum / 1.4426952 + 0.5); + if (f <= 1) { rice_k = 1; + } else if (f >= 31) { + rice_k = 31; + } else + rice_k = f; } return rice_k; @@ -293,7 +299,7 @@ static int do_decode(AVCodecContext *avctx, AVFrame *frame, int decorrelate, int dst[n] += (int)(P2 + P3) / 2 + (unsigned)p; break; case 8: - dst[n] += (int)(P2 + P3) / 2; + dst[n] += (int)(P2 + P3) / 2 + 0U; break; case 9: dst[n] += (int)(P2 * 2 + P3) / 3 + (unsigned)p; @@ -302,13 +308,13 @@ static int do_decode(AVCodecContext *avctx, AVFrame *frame, int decorrelate, int dst[n] += (int)(P2 + P3 * 2) / 3 + (unsigned)p; break; case 11: - dst[n] += (int)((unsigned)dst[A] + dst[B]) / 2; + dst[n] += (int)((unsigned)dst[A] + dst[B]) / 2 + 0U; break; case 12: dst[n] += (unsigned)dst[B]; break; case 13: - dst[n] += (int)(unsigned)(dst[D] + dst[B]) / 2; + dst[n] += (int)((unsigned)dst[D] + dst[B]) / 2 + 0U; break; case 14: dst[n] += (int)((unsigned)P2 + dst[A]) / 2 + (unsigned)p; @@ -320,7 +326,7 @@ static int do_decode(AVCodecContext *avctx, AVFrame *frame, int decorrelate, int cb->prev = prev; if (downsample) - dst[n] *= 256; + dst[n] *= 256U; dst[E] = dst[D]; dst[D] = dst[C]; @@ -335,7 +341,7 @@ static int do_decode(AVCodecContext *avctx, AVFrame *frame, int decorrelate, int if (nb_channels == 2 && ch == 1) { if (decorrelate) - dst[n] += s->decode_buffer[0][OFFSET+n]; + dst[n] += (unsigned)s->decode_buffer[0][OFFSET+n]; } if (downsample) @@ -351,7 +357,7 @@ static int osq_decode_block(AVCodecContext *avctx, AVFrame *frame) const int nb_channels = avctx->ch_layout.nb_channels; const int nb_samples = frame->nb_samples; OSQContext *s = avctx->priv_data; - const int factor = s->factor; + const unsigned factor = s->factor; int ret, decorrelate, downsample; GetBitContext *gb = &s->gb; diff --git a/libavcodec/parser.c b/libavcodec/parser.c index af17ee9c15..426cc314fb 100644 --- a/libavcodec/parser.c +++ b/libavcodec/parser.c @@ -236,6 +236,7 @@ int ff_combine_frame(ParseContext *pc, int next, } pc->buffer = new_buffer; memcpy(&pc->buffer[pc->index], *buf, *buf_size); + memset(&pc->buffer[pc->index + *buf_size], 0, AV_INPUT_BUFFER_PADDING_SIZE); pc->index += *buf_size; return -1; } diff --git a/libavcodec/pcm-bluray.c b/libavcodec/pcm-bluray.c index f65609514a..235020d78f 100644 --- a/libavcodec/pcm-bluray.c +++ b/libavcodec/pcm-bluray.c @@ -167,7 +167,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, AVFrame *frame, samples *= num_source_channels; if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) { #if HAVE_BIGENDIAN - bytestream2_get_buffer(&gb, dst16, buf_size); + bytestream2_get_buffer(&gb, (uint8_t*)dst16, buf_size); #else do { *dst16++ = bytestream2_get_be16u(&gb); @@ -187,7 +187,8 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, AVFrame *frame, if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) { do { #if HAVE_BIGENDIAN - bytestream2_get_buffer(&gb, dst16, avctx->ch_layout.nb_channels * 2); + bytestream2_get_buffer(&gb, (uint8_t*)dst16, + avctx->ch_layout.nb_channels * 2); dst16 += avctx->ch_layout.nb_channels; #else channel = avctx->ch_layout.nb_channels; diff --git a/libavcodec/pcm-dvd.c b/libavcodec/pcm-dvd.c index 419b2a138f..319746c62e 100644 --- a/libavcodec/pcm-dvd.c +++ b/libavcodec/pcm-dvd.c @@ -157,7 +157,7 @@ static void *pcm_dvd_decode_samples(AVCodecContext *avctx, const uint8_t *src, switch (avctx->bits_per_coded_sample) { case 16: { #if HAVE_BIGENDIAN - bytestream2_get_buffer(&gb, dst16, blocks * s->block_size); + bytestream2_get_buffer(&gb, (uint8_t*)dst16, blocks * s->block_size); dst16 += blocks * s->block_size / 2; #else int samples = blocks * avctx->ch_layout.nb_channels; diff --git a/libavcodec/pcm-dvdenc.c b/libavcodec/pcm-dvdenc.c index 1e7ee644f6..71e9b6915a 100644 --- a/libavcodec/pcm-dvdenc.c +++ b/libavcodec/pcm-dvdenc.c @@ -116,7 +116,7 @@ static int pcm_dvd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, { PCMDVDContext *s = avctx->priv_data; int samples = frame->nb_samples * avctx->ch_layout.nb_channels; - int64_t pkt_size = (frame->nb_samples / s->samples_per_block) * s->block_size + 3; + int64_t pkt_size = (int64_t)(frame->nb_samples / s->samples_per_block) * s->block_size + 3; int blocks = (pkt_size - 3) / s->block_size; const int16_t *src16; const int32_t *src32; diff --git a/libavcodec/pixlet.c b/libavcodec/pixlet.c index 6e925308b8..914f0636bc 100644 --- a/libavcodec/pixlet.c +++ b/libavcodec/pixlet.c @@ -230,8 +230,8 @@ static int read_high_coeffs(AVCodecContext *avctx, const uint8_t *src, int16_t * if (cnt1 >= length) { cnt1 = get_bits(bc, nbits); } else { - pfx = 14 + ((((uint64_t)(value - 14)) >> 32) & (value - 14)); - if (pfx < 1 || pfx > 25) + pfx = FFMIN(value, 14); + if (pfx < 1) return AVERROR_INVALIDDATA; cnt1 *= (1 << pfx) - 1; shbits = show_bits(bc, pfx); diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index de50e6a5b6..ea586332b2 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -85,11 +85,12 @@ typedef struct PNGDecContext { int have_clli; uint32_t clli_max; uint32_t clli_avg; - int have_mdvc; - uint16_t mdvc_primaries[3][2]; - uint16_t mdvc_white_point[2]; - uint32_t mdvc_max_lum; - uint32_t mdvc_min_lum; + /* Mastering Display Color Volume */ + int have_mdcv; + uint16_t mdcv_primaries[3][2]; + uint16_t mdcv_white_point[2]; + uint32_t mdcv_max_lum; + uint32_t mdcv_min_lum; enum PNGHeaderState hdr_state; enum PNGImageState pic_state; @@ -762,24 +763,24 @@ static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame) } } - if (s->have_mdvc) { - AVMasteringDisplayMetadata *mdvc; + if (s->have_mdcv) { + AVMasteringDisplayMetadata *mdcv; - ret = ff_decode_mastering_display_new(avctx, frame, &mdvc); + ret = ff_decode_mastering_display_new(avctx, frame, &mdcv); if (ret < 0) return ret; - if (mdvc) { - mdvc->has_primaries = 1; + if (mdcv) { + mdcv->has_primaries = 1; for (int i = 0; i < 3; i++) { - mdvc->display_primaries[i][0] = av_make_q(s->mdvc_primaries[i][0], 50000); - mdvc->display_primaries[i][1] = av_make_q(s->mdvc_primaries[i][1], 50000); + mdcv->display_primaries[i][0] = av_make_q(s->mdcv_primaries[i][0], 50000); + mdcv->display_primaries[i][1] = av_make_q(s->mdcv_primaries[i][1], 50000); } - mdvc->white_point[0] = av_make_q(s->mdvc_white_point[0], 50000); - mdvc->white_point[1] = av_make_q(s->mdvc_white_point[1], 50000); - mdvc->has_luminance = 1; - mdvc->max_luminance = av_make_q(s->mdvc_max_lum, 10000); - mdvc->min_luminance = av_make_q(s->mdvc_min_lum, 10000); + mdcv->white_point[0] = av_make_q(s->mdcv_white_point[0], 50000); + mdcv->white_point[1] = av_make_q(s->mdcv_white_point[1], 50000); + mdcv->has_luminance = 1; + mdcv->max_luminance = av_make_q(s->mdcv_max_lum, 10000); + mdcv->min_luminance = av_make_q(s->mdcv_min_lum, 10000); } } @@ -1081,17 +1082,20 @@ static int decode_sbit_chunk(AVCodecContext *avctx, PNGDecContext *s, return AVERROR_INVALIDDATA; } - channels = ff_png_get_nb_channels(s->color_type); + channels = s->color_type & PNG_COLOR_MASK_PALETTE ? 3 : ff_png_get_nb_channels(s->color_type); - if (bytestream2_get_bytes_left(gb) != channels) + if (bytestream2_get_bytes_left(gb) != channels) { + av_log(avctx, AV_LOG_ERROR, "Invalid sBIT size: %d, expected: %d\n", + bytestream2_get_bytes_left(gb), channels); return AVERROR_INVALIDDATA; + } for (int i = 0; i < channels; i++) { int b = bytestream2_get_byteu(gb); bits = FFMAX(b, bits); } - if (bits < 0 || bits > s->bit_depth) { + if (bits <= 0 || bits > (s->color_type & PNG_COLOR_MASK_PALETTE ? 8 : s->bit_depth)) { av_log(avctx, AV_LOG_ERROR, "Invalid significant bits: %d\n", bits); return AVERROR_INVALIDDATA; } @@ -1216,7 +1220,7 @@ static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s, return AVERROR_INVALIDDATA; } - if ((sequence_number == 0 || !s->last_picture.f->data[0]) && + if ((sequence_number == 0 || !s->last_picture.f) && dispose_op == APNG_DISPOSE_OP_PREVIOUS) { // No previous frame to revert to for the first frame // Spec says to just treat it as a APNG_DISPOSE_OP_BACKGROUND @@ -1569,20 +1573,20 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, s->clli_max = bytestream2_get_be32u(&gb_chunk); s->clli_avg = bytestream2_get_be32u(&gb_chunk); break; - case MKTAG('m', 'D', 'V', 'c'): + case MKTAG('m', 'D', 'C', 'v'): if (bytestream2_get_bytes_left(&gb_chunk) != 24) { - av_log(avctx, AV_LOG_WARNING, "Invalid mDVc chunk size: %d\n", bytestream2_get_bytes_left(&gb_chunk)); + av_log(avctx, AV_LOG_WARNING, "Invalid mDCv chunk size: %d\n", bytestream2_get_bytes_left(&gb_chunk)); break; } - s->have_mdvc = 1; + s->have_mdcv = 1; for (int i = 0; i < 3; i++) { - s->mdvc_primaries[i][0] = bytestream2_get_be16u(&gb_chunk); - s->mdvc_primaries[i][1] = bytestream2_get_be16u(&gb_chunk); + s->mdcv_primaries[i][0] = bytestream2_get_be16u(&gb_chunk); + s->mdcv_primaries[i][1] = bytestream2_get_be16u(&gb_chunk); } - s->mdvc_white_point[0] = bytestream2_get_be16u(&gb_chunk); - s->mdvc_white_point[1] = bytestream2_get_be16u(&gb_chunk); - s->mdvc_max_lum = bytestream2_get_be32u(&gb_chunk); - s->mdvc_min_lum = bytestream2_get_be32u(&gb_chunk); + s->mdcv_white_point[0] = bytestream2_get_be16u(&gb_chunk); + s->mdcv_white_point[1] = bytestream2_get_be16u(&gb_chunk); + s->mdcv_max_lum = bytestream2_get_be32u(&gb_chunk); + s->mdcv_min_lum = bytestream2_get_be32u(&gb_chunk); break; case MKTAG('I', 'E', 'N', 'D'): if (!(s->pic_state & PNG_ALLIMAGE)) diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index 28d645ea48..819cd83659 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -449,17 +449,17 @@ static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); if (side_data) { - AVMasteringDisplayMetadata *mdvc = (AVMasteringDisplayMetadata *) side_data->data; - if (mdvc->has_luminance && mdvc->has_primaries) { + AVMasteringDisplayMetadata *mdcv = (AVMasteringDisplayMetadata *) side_data->data; + if (mdcv->has_luminance && mdcv->has_primaries) { for (int i = 0; i < 3; i++) { - AV_WB16(s->buf + 2*i, PNG_Q2D(mdvc->display_primaries[i][0], 50000)); - AV_WB16(s->buf + 2*i + 2, PNG_Q2D(mdvc->display_primaries[i][1], 50000)); + AV_WB16(s->buf + 2*i, PNG_Q2D(mdcv->display_primaries[i][0], 50000)); + AV_WB16(s->buf + 2*i + 2, PNG_Q2D(mdcv->display_primaries[i][1], 50000)); } - AV_WB16(s->buf + 12, PNG_Q2D(mdvc->white_point[0], 50000)); - AV_WB16(s->buf + 14, PNG_Q2D(mdvc->white_point[1], 50000)); - AV_WB32(s->buf + 16, PNG_Q2D(mdvc->max_luminance, 10000)); - AV_WB32(s->buf + 20, PNG_Q2D(mdvc->min_luminance, 10000)); - png_write_chunk(&s->bytestream, MKTAG('m', 'D', 'V', 'c'), s->buf, 24); + AV_WB16(s->buf + 12, PNG_Q2D(mdcv->white_point[0], 50000)); + AV_WB16(s->buf + 14, PNG_Q2D(mdcv->white_point[1], 50000)); + AV_WB32(s->buf + 16, PNG_Q2D(mdcv->max_luminance, 10000)); + AV_WB32(s->buf + 20, PNG_Q2D(mdcv->min_luminance, 10000)); + png_write_chunk(&s->bytestream, MKTAG('m', 'D', 'C', 'v'), s->buf, 24); } } @@ -468,8 +468,9 @@ static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) if (png_get_gama(pict->color_trc, s->buf)) png_write_chunk(&s->bytestream, MKTAG('g', 'A', 'M', 'A'), s->buf, 4); - if (avctx->bits_per_raw_sample > 0 && avctx->bits_per_raw_sample < s->bit_depth) { - int len = ff_png_get_nb_channels(s->color_type); + if (avctx->bits_per_raw_sample > 0 && + avctx->bits_per_raw_sample < (s->color_type & PNG_COLOR_MASK_PALETTE ? 8 : s->bit_depth)) { + int len = s->color_type & PNG_COLOR_MASK_PALETTE ? 3 : ff_png_get_nb_channels(s->color_type); memset(s->buf, avctx->bits_per_raw_sample, len); png_write_chunk(&s->bytestream, MKTAG('s', 'B', 'I', 'T'), s->buf, len); } diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index acd77ea810..40cc2ae868 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -264,7 +264,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p, break; case AV_PIX_FMT_GBRPF32: if (!s->half) { - if (avctx->width * avctx->height * 12 > s->bytestream_end - s->bytestream) + if (avctx->width * avctx->height * 12LL > s->bytestream_end - s->bytestream) return AVERROR_INVALIDDATA; scale = 1.f / s->scale; if (s->endian) { diff --git a/libavcodec/ppc/h264dsp.c b/libavcodec/ppc/h264dsp.c index f50f2553a2..0650768d7b 100644 --- a/libavcodec/ppc/h264dsp.c +++ b/libavcodec/ppc/h264dsp.c @@ -663,7 +663,7 @@ void weight_h264_W_altivec(uint8_t *block, int stride, int height, DECLARE_ALIGNED(16, int32_t, temp)[4]; LOAD_ZERO; - offset <<= log2_denom; + offset *= 1 << log2_denom; if(log2_denom) offset += 1<<(log2_denom-1); temp[0] = log2_denom; temp[1] = weight; @@ -712,7 +712,7 @@ void biweight_h264_W_altivec(uint8_t *dst, uint8_t *src, int stride, int height, DECLARE_ALIGNED(16, int32_t, temp)[4]; LOAD_ZERO; - offset = ((offset + 1) | 1) << log2_denom; + offset = ((offset + 1) | 1) * (1 << log2_denom); temp[0] = log2_denom+1; temp[1] = weights; temp[2] = weightd; diff --git a/libavcodec/proresdec2.c b/libavcodec/proresdec2.c index 3a5b753430..faf6dfc976 100644 --- a/libavcodec/proresdec2.c +++ b/libavcodec/proresdec2.c @@ -510,7 +510,7 @@ static av_always_inline int decode_ac_coeffs(AVCodecContext *avctx, GetBitContex for (pos = block_mask;;) { bits_left = gb->size_in_bits - re_index; - if (!bits_left || (bits_left < 32 && !SHOW_UBITS(re, gb, bits_left))) + if (bits_left <= 0 || (bits_left < 32 && !SHOW_UBITS(re, gb, bits_left))) break; DECODE_CODEWORD(run, run_to_cb[FFMIN(run, 15)], LAST_SKIP_BITS); diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c index 02ab07d28e..b1a173e953 100644 --- a/libavcodec/proresenc_anatoliy.c +++ b/libavcodec/proresenc_anatoliy.c @@ -856,7 +856,8 @@ static av_cold int prores_encode_init(AVCodecContext *avctx) avctx->profile = AV_PROFILE_PRORES_4444; av_log(avctx, AV_LOG_INFO, "encoding with ProRes 4444+ (ap4h) profile\n"); - } + } else + av_assert0(0); } else if (avctx->profile < AV_PROFILE_PRORES_PROXY || avctx->profile > AV_PROFILE_PRORES_XQ) { av_log( diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index 90cc87e388..9d9f705ce4 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -342,7 +342,7 @@ static void get_slice_data(ProresContext *ctx, const uint16_t *src, static void get_alpha_data(ProresContext *ctx, const uint16_t *src, ptrdiff_t linesize, int x, int y, int w, int h, - int16_t *blocks, int mbs_per_slice, int abits) + uint16_t *blocks, int mbs_per_slice, int abits) { const int slice_width = 16 * mbs_per_slice; int i, j, copy_w, copy_h; diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c index 7563625627..452c0c6856 100644 --- a/libavcodec/qsv.c +++ b/libavcodec/qsv.c @@ -496,7 +496,7 @@ static int qsv_new_mfx_loader(AVCodecContext *avctx, mfxStatus sts; mfxLoader loader = NULL; mfxConfig cfg; - mfxVariant impl_value; + mfxVariant impl_value = {0}; loader = MFXLoad(); if (!loader) { diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index fd9267c6f4..bacb21afdf 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -378,9 +378,12 @@ static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVide q->frame_info = param->mfx.FrameInfo; - if (!avctx->hw_frames_ctx) - q->pool = av_buffer_pool_init(av_image_get_buffer_size(avctx->pix_fmt, - FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64), 1), av_buffer_allocz); + if (!avctx->hw_frames_ctx) { + ret = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64), 1); + if (ret < 0) + return ret; + q->pool = av_buffer_pool_init(ret, av_buffer_allocz); + } return 0; } diff --git a/libavcodec/r210enc.c b/libavcodec/r210enc.c index 91e3452874..ec1ebc8d60 100644 --- a/libavcodec/r210enc.c +++ b/libavcodec/r210enc.c @@ -35,7 +35,7 @@ static av_cold int encode_init(AVCodecContext *avctx) avctx->bits_per_coded_sample = 32; if (avctx->width > 0) - avctx->bit_rate = ff_guess_coded_bitrate(avctx) * aligned_width / avctx->width; + avctx->bit_rate = av_rescale(ff_guess_coded_bitrate(avctx), aligned_width, avctx->width); return 0; } diff --git a/libavcodec/rangecoder.h b/libavcodec/rangecoder.h index 89d178ac31..110908d6bd 100644 --- a/libavcodec/rangecoder.h +++ b/libavcodec/rangecoder.h @@ -62,7 +62,6 @@ void ff_build_rac_states(RangeCoder *c, int factor, int max_p); static inline void renorm_encoder(RangeCoder *c) { // FIXME: optimize - while (c->range < 0x100) { if (c->outstanding_byte < 0) { c->outstanding_byte = c->low >> 8; } else if (c->low <= 0xFF00) { @@ -81,7 +80,6 @@ static inline void renorm_encoder(RangeCoder *c) c->low = (c->low & 0xFF) << 8; c->range <<= 8; - } } static inline int get_rac_count(RangeCoder *c) @@ -108,7 +106,8 @@ static inline void put_rac(RangeCoder *c, uint8_t *const state, int bit) *state = c->one_state[*state]; } - renorm_encoder(c); + while (c->range < 0x100) + renorm_encoder(c); } static inline void refill(RangeCoder *c) diff --git a/libavcodec/riscv/flacdsp_rvv.S b/libavcodec/riscv/flacdsp_rvv.S index 2a0b50f7a9..5eb3c5bd55 100644 --- a/libavcodec/riscv/flacdsp_rvv.S +++ b/libavcodec/riscv/flacdsp_rvv.S @@ -55,11 +55,11 @@ func ff_flac_lpc32_rvv, zve32x vle32.v v16, (a0) sh2add a0, a2, a0 1: - vsetvli zero, a2, e32, m4, ta, ma + vsetvli t1, zero, e32, m4, ta, ma vwmul.vv v24, v8, v16 vsetvli zero, t2, e32, m4, tu, ma vwmacc.vv v24, v12, v20 - vsetvli zero, a2, e64, m8, ta, ma + vsetvli t1, zero, e64, m8, ta, ma vredsum.vs v24, v24, v0 lw t0, (a0) addi a4, a4, -1 diff --git a/libavcodec/riscv/lpc_init.c b/libavcodec/riscv/lpc_init.c index ab91956f2d..08efae4da7 100644 --- a/libavcodec/riscv/lpc_init.c +++ b/libavcodec/riscv/lpc_init.c @@ -36,7 +36,7 @@ av_cold void ff_lpc_init_riscv(LPCContext *c) if ((flags & AV_CPU_FLAG_RVV_F64) && (flags & AV_CPU_FLAG_RVB_ADDR)) { c->lpc_apply_welch_window = ff_lpc_apply_welch_window_rvv; - if (ff_get_rv_vlenb() >= c->max_order) + if (ff_get_rv_vlenb() > c->max_order) c->lpc_compute_autocorr = ff_lpc_compute_autocorr_rvv; } #endif diff --git a/libavcodec/riscv/lpc_rvv.S b/libavcodec/riscv/lpc_rvv.S index d4ea515fee..3fdf80ebed 100644 --- a/libavcodec/riscv/lpc_rvv.S +++ b/libavcodec/riscv/lpc_rvv.S @@ -87,6 +87,7 @@ func ff_lpc_apply_welch_window_rvv, zve64d endfunc func ff_lpc_compute_autocorr_rvv, zve64d + addi a2, a2, 1 li t0, 1 vsetvli zero, a2, e64, m8, ta, ma fcvt.d.l ft0, t0 diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index 914bde4a2a..ed630cd597 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -97,6 +97,8 @@ static av_cold void rv34_gen_vlc_ext(const uint8_t *bits, int size, VLC *vlc, uint16_t cw[MAX_VLC_SIZE]; int maxbits; + av_assert1(size > 0); + for (int i = 0; i < size; i++) counts[bits[i]]++; diff --git a/libavcodec/sbrdsp_template.c b/libavcodec/sbrdsp_template.c index c1e583ea56..75cf3dbdfc 100644 --- a/libavcodec/sbrdsp_template.c +++ b/libavcodec/sbrdsp_template.c @@ -373,4 +373,10 @@ const attribute_visibility_hidden DECLARE_ALIGNED(16, INTFLOAT, AAC_RENAME(ff_sb {Q31( 0.14130051758487f), Q31(-0.95090983575689f)}, {Q31(-0.47005496701697f), Q31(-0.37340549728647f)}, {Q31( 0.80705063769351f), Q31( 0.29653668284408f)}, {Q31(-0.38981478896926f), Q31( 0.89572605717087f)}, {Q31(-0.01053049862020f), Q31(-0.66959058036166f)}, {Q31(-0.91266367957293f), Q31(-0.11522938140034f)}, +#if ARCH_RISCV +{Q31( 0.54840422910309f), Q31( 0.75221367176302f)}, {Q31( 0.40009252867955f), Q31(-0.98929400334421f)}, +{Q31(-0.99867974711855f), Q31(-0.88147068645358f)}, {Q31(-0.95531076805040f), Q31( 0.90908757154593f)}, +{Q31(-0.45725933317144f), Q31(-0.56716323646760f)}, {Q31(-0.72929675029275f), Q31(-0.98008272727324f)}, +{Q31( 0.75622801399036f), Q31( 0.20950329995549f)}, {Q31( 0.07069442601050f), Q31(-0.78247898470706f)}, +#endif }; diff --git a/libavcodec/scpr3.c b/libavcodec/scpr3.c index 5271717ac7..e91c198308 100644 --- a/libavcodec/scpr3.c +++ b/libavcodec/scpr3.c @@ -465,6 +465,8 @@ static int decode_adaptive6(PixelModel3 *m, uint32_t code, uint32_t *value, return 0; grow_dec(m); c = add_dec(m, q, g, f); + if (c < 0) + return AVERROR_INVALIDDATA; } incr_cntdec(m, c); @@ -868,11 +870,11 @@ static int decode_unit3(SCPRContext *s, PixelModel3 *m, uint32_t code, uint32_t sync_code3(gb, rc); break; case 6: - if (!decode_adaptive6(m, code, value, &a, &b)) { + ret = decode_adaptive6(m, code, value, &a, &b); + if (!ret) ret = update_model6_to_7(m); - if (ret < 0) - return AVERROR_INVALIDDATA; - } + if (ret < 0) + return ret; decode3(gb, rc, a, b); sync_code3(gb, rc); break; diff --git a/libavcodec/sga.c b/libavcodec/sga.c index 4ced6e9890..acf8cec7f3 100644 --- a/libavcodec/sga.c +++ b/libavcodec/sga.c @@ -72,7 +72,7 @@ static int decode_palette(GetByteContext *gb, uint32_t *pal) return AVERROR_INVALIDDATA; memset(pal, 0, 16 * sizeof(*pal)); - init_get_bits8(&gbit, gb->buffer, 18); + (void)init_get_bits8(&gbit, gb->buffer, 18); for (int RGBIndex = 0; RGBIndex < 3; RGBIndex++) { for (int index = 0; index < 16; index++) { @@ -253,11 +253,13 @@ static int decode_palmapdata(AVCodecContext *avctx) const int bits = (s->nb_pal + 1) / 2; GetByteContext *gb = &s->gb; GetBitContext pm; + int ret; bytestream2_seek(gb, s->palmapdata_offset, SEEK_SET); if (bytestream2_get_bytes_left(gb) < s->palmapdata_size) return AVERROR_INVALIDDATA; - init_get_bits8(&pm, gb->buffer, s->palmapdata_size); + ret = init_get_bits8(&pm, gb->buffer, s->palmapdata_size); + av_assert1(ret >= 0); for (int y = 0; y < s->tiles_h; y++) { uint8_t *dst = s->palmapindex_data + y * s->tiles_w; @@ -276,11 +278,13 @@ static int decode_tiledata(AVCodecContext *avctx) SGAVideoContext *s = avctx->priv_data; GetByteContext *gb = &s->gb; GetBitContext tm; + int ret; bytestream2_seek(gb, s->tiledata_offset, SEEK_SET); if (bytestream2_get_bytes_left(gb) < s->tiledata_size) return AVERROR_INVALIDDATA; - init_get_bits8(&tm, gb->buffer, s->tiledata_size); + ret = init_get_bits8(&tm, gb->buffer, s->tiledata_size); + av_assert1(ret >= 0); for (int n = 0; n < s->nb_tiles; n++) { uint8_t *dst = s->tileindex_data + n * 64; diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 0ad95bf97e..66ff8dea3b 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -562,6 +562,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, AVFrame *frame, buf = &s->bitstream[s->bitstream_index]; buf_size += s->bitstream_size; s->bitstream_size = buf_size; + memset(buf + buf_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); /* do not decode until buffer has at least max_framesize bytes or * the end of the file has been reached */ diff --git a/libavcodec/snow.c b/libavcodec/snow.c index 59815d00d9..1b0fc6dc7d 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -427,7 +427,7 @@ av_cold int ff_snow_common_init(AVCodecContext *avctx){ !FF_ALLOCZ_TYPED_ARRAY(s->spatial_dwt_buffer, width * height) || //FIXME this does not belong here !FF_ALLOCZ_TYPED_ARRAY(s->temp_dwt_buffer, width) || !FF_ALLOCZ_TYPED_ARRAY(s->temp_idwt_buffer, width) || - !FF_ALLOCZ_TYPED_ARRAY(s->run_buffer, ((width + 1) >> 1) * ((height + 1) >> 1))) + !FF_ALLOCZ_TYPED_ARRAY(s->run_buffer, ((width + 1) >> 1) * ((height + 1) >> 1) + 1)) return AVERROR(ENOMEM); for(i=0; imy - top->my)); int s_context= 2*left->level + 2*top->level + tl->level + tr->level; int ref, best_ref, ref_score, ref_mx, ref_my; + int range = MAX_MV >> (1 + qpel); av_assert0(sizeof(s->block_state) >= 256); if(s->keyframe){ @@ -452,6 +453,11 @@ static int encode_q_branch(SnowEncContext *enc, int level, int x, int y) c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; + c->xmin = FFMAX(c->xmin,-range); + c->xmax = FFMIN(c->xmax, range); + c->ymin = FFMAX(c->ymin,-range); + c->ymax = FFMIN(c->ymax, range); + if(P_LEFT[0] > (c->xmax<xmax< (c->ymax<ymax< (c->xmax<xmax<size < s->mb_width * s->mb_height / 8) + return AVERROR_INVALIDDATA; + s->pict_type = s->slice_type; if (s->pict_type != AV_PICTURE_TYPE_B) diff --git a/libavcodec/targaenc.c b/libavcodec/targaenc.c index d9c500b97d..8f496c62bd 100644 --- a/libavcodec/targaenc.c +++ b/libavcodec/targaenc.c @@ -21,6 +21,7 @@ #include +#include "libavutil/avassert.h" #include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/intreadwrite.h" @@ -89,10 +90,11 @@ static int targa_encode_frame(AVCodecContext *avctx, AVPacket *pkt, TargaContext *s = avctx->priv_data; int bpp, picsize, datasize = -1, ret, i; uint8_t *out; + int maxpal = 32*32; picsize = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1); - if ((ret = ff_alloc_packet(avctx, pkt, picsize + 45)) < 0) + if ((ret = ff_alloc_packet(avctx, pkt, picsize + 45 + maxpal)) < 0) return ret; /* zero out the header and only set applicable fields */ @@ -125,6 +127,7 @@ static int targa_encode_frame(AVCodecContext *avctx, AVPacket *pkt, AV_WL24(pkt->data + 18 + 3 * i, *(uint32_t *)(p->data[1] + i * 4)); } out += 32 * pal_bpp; /* skip past the palette we just output */ + av_assert0(32 * pal_bpp <= maxpal); break; } case AV_PIX_FMT_GRAY8: diff --git a/libavcodec/tests/bitstream_template.c b/libavcodec/tests/bitstream_template.c index ef59845154..b4c8821a90 100644 --- a/libavcodec/tests/bitstream_template.c +++ b/libavcodec/tests/bitstream_template.c @@ -61,6 +61,7 @@ int main(int argc, char **argv) uint64_t val, val1; int32_t sval, sval1; unsigned count; + int ret; /* generate random input, using a given or random seed */ if (argc > 1) @@ -74,7 +75,8 @@ int main(int argc, char **argv) for (unsigned i = 0; i < SIZE; i++) buf[i] = av_lfg_get(&lfg); - bits_init8 (&bc, buf, SIZE); + ret = bits_init8 (&bc, buf, SIZE); + av_assert0(ret >= 0); init_put_bits(&pb, dst, SIZE); /* use a random sequence of bitreading operations to transfer data diff --git a/libavcodec/tests/dct.c b/libavcodec/tests/dct.c index 010d0c1ac3..17a0814459 100644 --- a/libavcodec/tests/dct.c +++ b/libavcodec/tests/dct.c @@ -226,8 +226,8 @@ static int dct_error(const struct algo *dct, int test, int is_idct, int speed, c v = abs(err); if (v > err_inf) err_inf = v; - err2_matrix[i] += v * v; - err2 += v * v; + err2_matrix[i] += v * (int64_t)v; + err2 += v * (int64_t)v; sysErr[i] += block[i] - block1[i]; blockSumErr += v; if (abs(block[i]) > maxout) diff --git a/libavcodec/tests/jpeg2000dwt.c b/libavcodec/tests/jpeg2000dwt.c index 0e5a6ed947..520ecc05a3 100644 --- a/libavcodec/tests/jpeg2000dwt.c +++ b/libavcodec/tests/jpeg2000dwt.c @@ -52,12 +52,12 @@ static int test_dwt(int *array, int *ref, int border[2][2], int decomp_levels, i return 1; } for (j = 0; j max_diff) { + if (FFABS(array[j] - (int64_t)ref[j]) > max_diff) { fprintf(stderr, "missmatch at %d (%d != %d) decomp:%d border %d %d %d %d\n", j, array[j], ref[j],decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1]); return 2; } - err2 += (array[j] - ref[j]) * (array[j] - ref[j]); + err2 += (array[j] - ref[j]) * (int64_t)(array[j] - ref[j]); array[j] = ref[j]; } ff_dwt_destroy(s); diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 7ce1ab32f6..bfa345b3d8 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -421,7 +421,8 @@ static void av_always_inline horizontal_fill(TiffContext *s, uint8_t shift = is_dng ? 0 : 16 - bpp; GetBitContext gb; - init_get_bits8(&gb, src, width); + int ret = init_get_bits8(&gb, src, width); + av_assert1(ret >= 0); for (int i = 0; i < s->width; i++) { dst16[i] = get_bits(&gb, bpp) << shift; } @@ -455,7 +456,8 @@ static void unpack_gray(TiffContext *s, AVFrame *p, GetBitContext gb; uint16_t *dst = (uint16_t *)(p->data[0] + lnum * p->linesize[0]); - init_get_bits8(&gb, src, width); + int ret = init_get_bits8(&gb, src, width); + av_assert1(ret >= 0); for (int i = 0; i < s->width; i++) { dst[i] = get_bits(&gb, bpp); @@ -1295,9 +1297,13 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame) s->is_thumbnail = (value != 0); break; case TIFF_WIDTH: + if (value > INT_MAX) + return AVERROR_INVALIDDATA; s->width = value; break; case TIFF_HEIGHT: + if (value > INT_MAX) + return AVERROR_INVALIDDATA; s->height = value; break; case TIFF_BPP: @@ -1429,12 +1435,18 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame) s->tile_byte_counts_offset = off; break; case TIFF_TILE_LENGTH: + if (value > INT_MAX) + return AVERROR_INVALIDDATA; s->tile_length = value; break; case TIFF_TILE_WIDTH: + if (value > INT_MAX) + return AVERROR_INVALIDDATA; s->tile_width = value; break; case TIFF_PREDICTOR: + if (value > INT_MAX) + return AVERROR_INVALIDDATA; s->predictor = value; break; case TIFF_SUB_IFDS: @@ -1579,12 +1591,18 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame) } break; case TIFF_T4OPTIONS: - if (s->compr == TIFF_G3) + if (s->compr == TIFF_G3) { + if (value > INT_MAX) + return AVERROR_INVALIDDATA; s->fax_opts = value; + } break; case TIFF_T6OPTIONS: - if (s->compr == TIFF_G4) + if (s->compr == TIFF_G4) { + if (value > INT_MAX) + return AVERROR_INVALIDDATA; s->fax_opts = value; + } break; #define ADD_METADATA(count, name, sep)\ if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\ diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 337c00e789..c6785eeec1 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -259,6 +259,9 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, if (s->codec_id == AV_CODEC_ID_SVQ1) { w_align = 64; h_align = 64; + } else if (s->codec_id == AV_CODEC_ID_SNOW) { + w_align = 16; + h_align = 16; } break; case AV_PIX_FMT_RGB555: @@ -720,7 +723,7 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba, case AV_CODEC_ID_ADPCM_IMA_WAV: if (bps < 2 || bps > 5) return 0; - tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8); + tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8LL); break; case AV_CODEC_ID_ADPCM_IMA_DK3: tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch); diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c index ce5d00f7af..0c2e67e282 100644 --- a/libavcodec/utvideodec.c +++ b/libavcodec/utvideodec.c @@ -120,7 +120,7 @@ static int build_huff(UtvideoContext *c, const uint8_t *src, VLC *vlc, i = 0; \ for (; CACHED_BITSTREAM_READER && i < width-end && get_bits_left(&gb) > 0;) {\ ret = get_vlc_multi(&gb, (uint8_t *)buf + i * b, multi.table, \ - vlc.table, VLC_BITS, 3); \ + vlc.table, VLC_BITS, 3, b); \ if (ret > 0) \ i += ret; \ if (ret <= 0) \ diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c index 36dcb8283a..ad8d73fbb4 100644 --- a/libavcodec/utvideoenc.c +++ b/libavcodec/utvideoenc.c @@ -239,7 +239,7 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx) * - Compression mode (none/huff) * And write the flags. */ - c->flags = (c->slices - 1) << 24; + c->flags = (c->slices - 1U) << 24; c->flags |= 0 << 11; // bit field to signal interlaced encoding mode c->flags |= c->compression; diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c index 1f9a6071ba..38811630cc 100644 --- a/libavcodec/vaapi_av1.c +++ b/libavcodec/vaapi_av1.c @@ -19,6 +19,7 @@ */ #include "libavutil/frame.h" +#include "libavutil/mem.h" #include "hwaccel_internal.h" #include "vaapi_decode.h" #include "internal.h" @@ -42,6 +43,9 @@ typedef struct VAAPIAV1DecContext { */ VAAPIAV1FrameRef ref_tab[AV1_NUM_REF_FRAMES]; AVFrame *tmp_frame; + + int nb_slice_params; + VASliceParameterBufferAV1 *slice_params; } VAAPIAV1DecContext; static VASurfaceID vaapi_av1_surface_id(AV1Frame *vf) @@ -97,6 +101,8 @@ static int vaapi_av1_decode_uninit(AVCodecContext *avctx) for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) av_frame_free(&ctx->ref_tab[i].frame); + av_freep(&ctx->slice_params); + return ff_vaapi_decode_uninit(avctx); } @@ -220,7 +226,7 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx, .error_resilient_mode = frame_header->error_resilient_mode, .disable_cdf_update = frame_header->disable_cdf_update, .allow_screen_content_tools = frame_header->allow_screen_content_tools, - .force_integer_mv = frame_header->force_integer_mv, + .force_integer_mv = s->cur_frame.force_integer_mv, .allow_intrabc = frame_header->allow_intrabc, .use_superres = frame_header->use_superres, .allow_high_precision_mv = frame_header->allow_high_precision_mv, @@ -393,13 +399,24 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx, { const AV1DecContext *s = avctx->priv_data; VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private; - VASliceParameterBufferAV1 slice_param; - int err = 0; + VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data; + int err, nb_params; + + nb_params = s->tg_end - s->tg_start + 1; + if (ctx->nb_slice_params < nb_params) { + ctx->slice_params = av_realloc_array(ctx->slice_params, + nb_params, + sizeof(*ctx->slice_params)); + if (!ctx->slice_params) { + ctx->nb_slice_params = 0; + err = AVERROR(ENOMEM); + goto fail; + } + ctx->nb_slice_params = nb_params; + } for (int i = s->tg_start; i <= s->tg_end; i++) { - memset(&slice_param, 0, sizeof(VASliceParameterBufferAV1)); - - slice_param = (VASliceParameterBufferAV1) { + ctx->slice_params[i - s->tg_start] = (VASliceParameterBufferAV1) { .slice_data_size = s->tile_group_info[i].tile_size, .slice_data_offset = s->tile_group_info[i].tile_offset, .slice_data_flag = VA_SLICE_DATA_FLAG_ALL, @@ -408,18 +425,20 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx, .tg_start = s->tg_start, .tg_end = s->tg_end, }; - - err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param, - sizeof(VASliceParameterBufferAV1), - buffer, - size); - if (err) { - ff_vaapi_decode_cancel(avctx, pic); - return err; - } } + err = ff_vaapi_decode_make_slice_buffer(avctx, pic, ctx->slice_params, nb_params, + sizeof(VASliceParameterBufferAV1), + buffer, + size); + if (err) + goto fail; + return 0; + +fail: + ff_vaapi_decode_cancel(avctx, pic); + return err; } const FFHWAccel ff_av1_vaapi_hwaccel = { diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c index cca94b5336..cd11093fea 100644 --- a/libavcodec/vaapi_decode.c +++ b/libavcodec/vaapi_decode.c @@ -62,6 +62,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx, int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, const void *params_data, + int nb_params, size_t params_size, const void *slice_data, size_t slice_size) @@ -87,7 +88,7 @@ int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx, vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, VASliceParameterBufferType, - params_size, 1, (void*)params_data, + params_size, nb_params, (void*)params_data, &pic->slice_buffers[index]); if (vas != VA_STATUS_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to create slice " diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h index 6beda14e52..702171e108 100644 --- a/libavcodec/vaapi_decode.h +++ b/libavcodec/vaapi_decode.h @@ -73,6 +73,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx, int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, const void *params_data, + int nb_params, size_t params_size, const void *slice_data, size_t slice_size); diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 940f0678a5..b8765a19c7 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -1805,9 +1805,17 @@ static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx) int i, first = 1, res; supported_va_rc_modes = rc_attr.value; - if (ctx->blbrc && !(supported_va_rc_modes & VA_RC_MB)) { + if (ctx->blbrc) { +#if VA_CHECK_VERSION(0, 39, 2) + if (!(supported_va_rc_modes & VA_RC_MB)) { + ctx->blbrc = 0; + av_log(avctx, AV_LOG_WARNING, "Driver does not support BLBRC.\n"); + } +#else ctx->blbrc = 0; - av_log(avctx, AV_LOG_WARNING, "Driver does not support BLBRC.\n"); + av_log(avctx, AV_LOG_WARNING, "Please consider to update to VAAPI 0.39.2 " + "or above, which can support BLBRC.\n"); +#endif } for (i = 0; i < FF_ARRAY_ELEMS(vaapi_encode_rc_modes); i++) { @@ -1961,7 +1969,10 @@ rc_mode_found: if (ctx->explicit_qp) { rc_quality = ctx->explicit_qp; } else if (avctx->global_quality > 0) { - rc_quality = avctx->global_quality; + if (avctx->flags & AV_CODEC_FLAG_QSCALE) + rc_quality = avctx->global_quality / FF_QP2LAMBDA; + else + rc_quality = avctx->global_quality; } else { rc_quality = ctx->codec->default_quality; av_log(avctx, AV_LOG_WARNING, "No quality level set; " @@ -2032,7 +2043,11 @@ rc_mode_found: ctx->config_attributes[ctx->nb_config_attributes++] = (VAConfigAttrib) { .type = VAConfigAttribRateControl, +#if VA_CHECK_VERSION(0, 39, 2) .value = ctx->blbrc ? ctx->va_rc_mode | VA_RC_MB : ctx->va_rc_mode, +#else + .value = ctx->va_rc_mode, +#endif }; } @@ -2061,10 +2076,12 @@ rc_mode_found: #if VA_CHECK_VERSION(1, 1, 0) .ICQ_quality_factor = av_clip(rc_quality, 1, 51), .max_qp = (avctx->qmax > 0 ? avctx->qmax : 0), - .rc_flags.bits.mb_rate_control = ctx->blbrc ? 1 : 2, #endif #if VA_CHECK_VERSION(1, 3, 0) .quality_factor = rc_quality, +#endif +#if VA_CHECK_VERSION(0, 39, 2) + .rc_flags.bits.mb_rate_control = ctx->blbrc ? 1 : 2, #endif }; vaapi_encode_add_global_param(avctx, @@ -2980,12 +2997,14 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx) ff_refstruct_pool_uninit(&ctx->output_buffer_pool); if (ctx->va_context != VA_INVALID_ID) { - vaDestroyContext(ctx->hwctx->display, ctx->va_context); + if (ctx->hwctx) + vaDestroyContext(ctx->hwctx->display, ctx->va_context); ctx->va_context = VA_INVALID_ID; } if (ctx->va_config != VA_INVALID_ID) { - vaDestroyConfig(ctx->hwctx->display, ctx->va_config); + if (ctx->hwctx) + vaDestroyConfig(ctx->hwctx->display, ctx->va_config); ctx->va_config = VA_INVALID_ID; } diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c index 55cf5a05ee..b47531ce1c 100644 --- a/libavcodec/vaapi_h264.c +++ b/libavcodec/vaapi_h264.c @@ -375,7 +375,7 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx, slice_param.chroma_offset_l1); err = ff_vaapi_decode_make_slice_buffer(avctx, pic, - &slice_param, sizeof(slice_param), + &slice_param, 1, sizeof(slice_param), buffer, size); if (err) { ff_vaapi_decode_cancel(avctx, pic); diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c index 3bdd2dd1b8..3937b7574a 100644 --- a/libavcodec/vaapi_hevc.c +++ b/libavcodec/vaapi_hevc.c @@ -353,7 +353,7 @@ static int vaapi_hevc_end_frame(AVCodecContext *avctx) if (pic->last_size) { last_slice_param->LongSliceFlags.fields.LastSliceOfPic = 1; ret = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic, - &pic->last_slice_param, slice_param_size, + &pic->last_slice_param, 1, slice_param_size, pic->last_buffer, pic->last_size); if (ret < 0) goto fail; @@ -471,7 +471,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx, if (!sh->first_slice_in_pic_flag) { err = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic, - &pic->last_slice_param, slice_param_size, + &pic->last_slice_param, 1, slice_param_size, pic->last_buffer, pic->last_size); pic->last_buffer = NULL; pic->last_size = 0; diff --git a/libavcodec/vaapi_mjpeg.c b/libavcodec/vaapi_mjpeg.c index 5b8d47bb2a..9557cf5f9b 100644 --- a/libavcodec/vaapi_mjpeg.c +++ b/libavcodec/vaapi_mjpeg.c @@ -131,7 +131,7 @@ static int vaapi_mjpeg_decode_slice(AVCodecContext *avctx, sp.components[i].ac_table_selector = s->ac_index[i]; } - err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, sizeof(sp), buffer, size); + err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, 1, sizeof(sp), buffer, size); if (err) goto fail; diff --git a/libavcodec/vaapi_mpeg2.c b/libavcodec/vaapi_mpeg2.c index eeb4e87321..171a742c7f 100644 --- a/libavcodec/vaapi_mpeg2.c +++ b/libavcodec/vaapi_mpeg2.c @@ -162,7 +162,7 @@ static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer }; err = ff_vaapi_decode_make_slice_buffer(avctx, pic, - &slice_param, sizeof(slice_param), + &slice_param, 1, sizeof(slice_param), buffer, size); if (err < 0) { ff_vaapi_decode_cancel(avctx, pic); diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c index 363b686e42..612de10cd7 100644 --- a/libavcodec/vaapi_mpeg4.c +++ b/libavcodec/vaapi_mpeg4.c @@ -169,7 +169,7 @@ static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer }; err = ff_vaapi_decode_make_slice_buffer(avctx, pic, - &slice_param, sizeof(slice_param), + &slice_param, 1, sizeof(slice_param), buffer, size); if (err < 0) { ff_vaapi_decode_cancel(avctx, pic); diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c index 09a5c852fc..0339ccc043 100644 --- a/libavcodec/vaapi_vc1.c +++ b/libavcodec/vaapi_vc1.c @@ -489,7 +489,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, }; err = ff_vaapi_decode_make_slice_buffer(avctx, pic, - &slice_param, sizeof(slice_param), + &slice_param, 1, sizeof(slice_param), buffer, size); if (err < 0) { ff_vaapi_decode_cancel(avctx, pic); diff --git a/libavcodec/vaapi_vp8.c b/libavcodec/vaapi_vp8.c index 31137a45bd..66fdde1f39 100644 --- a/libavcodec/vaapi_vp8.c +++ b/libavcodec/vaapi_vp8.c @@ -209,7 +209,7 @@ static int vaapi_vp8_decode_slice(AVCodecContext *avctx, for (i = 0; i < 8; i++) sp.partition_size[i+1] = s->coeff_partition_size[i]; - err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, sizeof(sp), data, data_size); + err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, 1, sizeof(sp), data, data_size); if (err) goto fail; diff --git a/libavcodec/vaapi_vp9.c b/libavcodec/vaapi_vp9.c index 9dc7d5e72b..ff11022db7 100644 --- a/libavcodec/vaapi_vp9.c +++ b/libavcodec/vaapi_vp9.c @@ -158,7 +158,7 @@ static int vaapi_vp9_decode_slice(AVCodecContext *avctx, } err = ff_vaapi_decode_make_slice_buffer(avctx, pic, - &slice_param, sizeof(slice_param), + &slice_param, 1, sizeof(slice_param), buffer, size); if (err) { ff_vaapi_decode_cancel(avctx, pic); diff --git a/libavcodec/vble.c b/libavcodec/vble.c index 7711bf1bb1..d27ab658dd 100644 --- a/libavcodec/vble.c +++ b/libavcodec/vble.c @@ -191,6 +191,9 @@ static av_cold int vble_decode_init(AVCodecContext *avctx) ctx->size = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1); + if (ctx->size < 0) + return ctx->size; + ctx->val = av_malloc_array(ctx->size, sizeof(*ctx->val)); if (!ctx->val) { diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c index a6ee4922f9..d593878140 100644 --- a/libavcodec/vc1_block.c +++ b/libavcodec/vc1_block.c @@ -1297,6 +1297,7 @@ static int vc1_decode_p_mb(VC1Context *v) int dst_idx, off; int skipped, fourmv; int block_cbp = 0, pat, block_tt = 0, block_intra = 0; + int ret; mquant = v->pq; /* lossy initialization */ @@ -1355,8 +1356,10 @@ static int vc1_decode_p_mb(VC1Context *v) if (i == 1 || i == 3 || s->mb_x) v->c_avail = v->mb_type[0][s->block_index[i] - 1]; - vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant, - (i & 4) ? v->codingset2 : v->codingset); + ret = vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant, + (i & 4) ? v->codingset2 : v->codingset); + if (ret < 0) + return ret; if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(v->block[v->cur_blk_idx][block_map[i]]); @@ -1458,8 +1461,10 @@ static int vc1_decode_p_mb(VC1Context *v) if (i == 1 || i == 3 || s->mb_x) v->c_avail = v->mb_type[0][s->block_index[i] - 1]; - vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, is_coded[i], mquant, - (i & 4) ? v->codingset2 : v->codingset); + ret = vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, is_coded[i], mquant, + (i & 4) ? v->codingset2 : v->codingset); + if (ret < 0) + return ret; if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(v->block[v->cur_blk_idx][block_map[i]]); @@ -1530,6 +1535,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v) int block_cbp = 0, pat, block_tt = 0; int idx_mbmode = 0, mvbp; int fieldtx; + int ret; mquant = v->pq; /* Lossy initialization */ @@ -1602,8 +1608,10 @@ static int vc1_decode_p_mb_intfr(VC1Context *v) if (i == 1 || i == 3 || s->mb_x) v->c_avail = v->mb_type[0][s->block_index[i] - 1]; - vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant, - (i & 4) ? v->codingset2 : v->codingset); + ret = vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant, + (i & 4) ? v->codingset2 : v->codingset); + if (ret < 0) + return ret; if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(v->block[v->cur_blk_idx][block_map[i]]); @@ -1739,6 +1747,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v) int pred_flag = 0; int block_cbp = 0, pat, block_tt = 0; int idx_mbmode = 0; + int ret; mquant = v->pq; /* Lossy initialization */ @@ -1770,8 +1779,10 @@ static int vc1_decode_p_mb_intfi(VC1Context *v) if (i == 1 || i == 3 || s->mb_x) v->c_avail = v->mb_type[0][s->block_index[i] - 1]; - vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant, - (i & 4) ? v->codingset2 : v->codingset); + ret = vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant, + (i & 4) ? v->codingset2 : v->codingset); + if (ret < 0) + return ret; if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(v->block[v->cur_blk_idx][block_map[i]]); @@ -1862,6 +1873,7 @@ static int vc1_decode_b_mb(VC1Context *v) int skipped, direct; int dmv_x[2], dmv_y[2]; int bmvtype = BMV_TYPE_BACKWARD; + int ret; mquant = v->pq; /* lossy initialization */ s->mb_intra = 0; @@ -1974,8 +1986,10 @@ static int vc1_decode_b_mb(VC1Context *v) if (i == 1 || i == 3 || s->mb_x) v->c_avail = v->mb_type[0][s->block_index[i] - 1]; - vc1_decode_intra_block(v, s->block[i], i, val, mquant, - (i & 4) ? v->codingset2 : v->codingset); + ret = vc1_decode_intra_block(v, s->block[i], i, val, mquant, + (i & 4) ? v->codingset2 : v->codingset); + if (ret < 0) + return ret; if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); @@ -2021,6 +2035,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v) int bmvtype = BMV_TYPE_BACKWARD; int block_cbp = 0, pat, block_tt = 0; int idx_mbmode; + int ret; mquant = v->pq; /* Lossy initialization */ s->mb_intra = 0; @@ -2053,8 +2068,10 @@ static int vc1_decode_b_mb_intfi(VC1Context *v) if (i == 1 || i == 3 || s->mb_x) v->c_avail = v->mb_type[0][s->block_index[i] - 1]; - vc1_decode_intra_block(v, s->block[i], i, val, mquant, - (i & 4) ? v->codingset2 : v->codingset); + ret = vc1_decode_intra_block(v, s->block[i], i, val, mquant, + (i & 4) ? v->codingset2 : v->codingset); + if (ret < 0) + return ret; if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); @@ -2191,6 +2208,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v) int stride_y, fieldtx; int bmvtype = BMV_TYPE_BACKWARD; int dir, dir2; + int ret; mquant = v->pq; /* Lossy initialization */ s->mb_intra = 0; @@ -2247,8 +2265,10 @@ static int vc1_decode_b_mb_intfr(VC1Context *v) if (i == 1 || i == 3 || s->mb_x) v->c_avail = v->mb_type[0][s->block_index[i] - 1]; - vc1_decode_intra_block(v, s->block[i], i, val, mquant, - (i & 4) ? v->codingset2 : v->codingset); + ret = vc1_decode_intra_block(v, s->block[i], i, val, mquant, + (i & 4) ? v->codingset2 : v->codingset); + if (ret < 0) + return ret; if (CONFIG_GRAY && i > 3 && (s->avctx->flags & AV_CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); @@ -2782,6 +2802,7 @@ static void vc1_decode_p_blocks(VC1Context *v) { MpegEncContext *s = &v->s; int apply_loop_filter; + int ret; /* select coding mode used for VLC tables selection */ switch (v->c_ac_table_index) { @@ -2824,22 +2845,22 @@ static void vc1_decode_p_blocks(VC1Context *v) } if (v->fcm == ILACE_FIELD) { - vc1_decode_p_mb_intfi(v); + ret = vc1_decode_p_mb_intfi(v); if (apply_loop_filter) ff_vc1_p_loop_filter(v); } else if (v->fcm == ILACE_FRAME) { - vc1_decode_p_mb_intfr(v); + ret = vc1_decode_p_mb_intfr(v); if (apply_loop_filter) ff_vc1_p_intfr_loop_filter(v); } else { - vc1_decode_p_mb(v); + ret = vc1_decode_p_mb(v); if (apply_loop_filter) ff_vc1_p_loop_filter(v); } - if (get_bits_left(&s->gb) < 0 || get_bits_count(&s->gb) < 0) { + if (ret < 0 || get_bits_left(&s->gb) < 0 || get_bits_count(&s->gb) < 0) { // TODO: may need modification to handle slice coding ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR); - av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", + av_log(s->avctx, AV_LOG_ERROR, "Error or Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), s->gb.size_in_bits, s->mb_x, s->mb_y); return; } diff --git a/libavcodec/vc1_loopfilter.c b/libavcodec/vc1_loopfilter.c index 0f990cccef..ee694ede28 100644 --- a/libavcodec/vc1_loopfilter.c +++ b/libavcodec/vc1_loopfilter.c @@ -1125,10 +1125,7 @@ static av_always_inline void vc1_b_h_intfi_loop_filter(VC1Context *v, uint8_t *d dst = dest + (block_num & 2) * 4 * s->linesize + (block_num & 1) * 8; if (!(flags & RIGHT_EDGE) || !(block_num & 5)) { - if (block_num > 3) - v->vc1dsp.vc1_h_loop_filter8(dst + 8, linesize, pq); - else - v->vc1dsp.vc1_h_loop_filter8(dst + 8, linesize, pq); + v->vc1dsp.vc1_h_loop_filter8(dst + 8, linesize, pq); } tt = ttblk[0] >> (block_num * 4) & 0xf; diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 3ca478e82a..f01bd50aff 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -378,7 +378,7 @@ static av_cold int vc1_decode_init_alloc_tables(VC1Context *v) if (!v->block || !v->cbp_base) return AVERROR(ENOMEM); v->cbp = v->cbp_base + 2 * s->mb_stride; - v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 3 * s->mb_stride); + v->ttblk_base = av_mallocz(sizeof(v->ttblk_base[0]) * 3 * s->mb_stride); if (!v->ttblk_base) return AVERROR(ENOMEM); v->ttblk = v->ttblk_base + 2 * s->mb_stride; @@ -392,7 +392,7 @@ static av_cold int vc1_decode_init_alloc_tables(VC1Context *v) v->luma_mv = v->luma_mv_base + 2 * s->mb_stride; /* allocate block type info in that way so it could be used with s->block_index[] */ - v->mb_type_base = av_malloc(s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2); + v->mb_type_base = av_mallocz(s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2); if (!v->mb_type_base) return AVERROR(ENOMEM); v->mb_type[0] = v->mb_type_base + s->b8_stride + 1; @@ -786,6 +786,7 @@ av_cold int ff_vc1_decode_end(AVCodecContext *avctx) for (i = 0; i < 4; i++) av_freep(&v->sr_rows[i >> 1][i & 1]); ff_mpv_common_end(&v->s); + memset(v->s.block_index, 0, sizeof(v->s.block_index)); av_freep(&v->mv_type_mb_plane); av_freep(&v->direct_mb_plane); av_freep(&v->forward_mb_plane); diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c index 6fbac29032..c442179a3e 100644 --- a/libavcodec/vc2enc.c +++ b/libavcodec/vc2enc.c @@ -185,7 +185,9 @@ typedef struct VC2EncContext { static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val) { int i; - int pbits = 0, bits = 0, topbit = 1, maxval = 1; + int bits = 0; + unsigned topbit = 1, maxval = 1; + uint64_t pbits = 0; if (!val++) { put_bits(pb, 1, 1); @@ -202,12 +204,13 @@ static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val) for (i = 0; i < bits; i++) { topbit >>= 1; + av_assert2(pbits <= UINT64_MAX>>3); pbits <<= 2; if (val & topbit) pbits |= 0x1; } - put_bits(pb, bits*2 + 1, (pbits << 1) | 1); + put_bits64(pb, bits*2 + 1, (pbits << 1) | 1); } static av_always_inline int count_vc2_ue_uint(uint32_t val) @@ -982,7 +985,7 @@ static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } s->slice_min_bytes = s->slice_max_bytes - s->slice_max_bytes*(s->tolerance/100.0f); - if (s->slice_min_bytes < 0) + if (s->slice_min_bytes < 0 || s->slice_max_bytes > INT_MAX >> 3) return AVERROR(EINVAL); ret = encode_frame(s, avpkt, frame, aux_data, header_size, s->interlaced); diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index 15c34d59c3..5ea9afee22 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -2905,6 +2905,12 @@ static const AVOption h264_options[] = { { NULL }, }; +static const FFCodecDefault vt_defaults[] = { + {"qmin", "-1"}, + {"qmax", "-1"}, + {NULL}, +}; + static const AVClass h264_videotoolbox_class = { .class_name = "h264_videotoolbox", .item_name = av_default_item_name, @@ -2920,6 +2926,7 @@ const FFCodec ff_h264_videotoolbox_encoder = { .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, .priv_data_size = sizeof(VTEncContext), .p.pix_fmts = avc_pix_fmts, + .defaults = vt_defaults, .init = vtenc_init, FF_CODEC_ENCODE_CB(vtenc_frame), .close = vtenc_close, @@ -2957,6 +2964,7 @@ const FFCodec ff_hevc_videotoolbox_encoder = { AV_CODEC_CAP_HARDWARE, .priv_data_size = sizeof(VTEncContext), .p.pix_fmts = hevc_pix_fmts, + .defaults = vt_defaults, .init = vtenc_init, FF_CODEC_ENCODE_CB(vtenc_frame), .close = vtenc_close, @@ -2996,6 +3004,7 @@ const FFCodec ff_prores_videotoolbox_encoder = { AV_CODEC_CAP_HARDWARE, .priv_data_size = sizeof(VTEncContext), .p.pix_fmts = prores_pix_fmts, + .defaults = vt_defaults, .init = vtenc_init, FF_CODEC_ENCODE_CB(vtenc_frame), .close = vtenc_close, diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c index 78510e30d6..7d940915df 100644 --- a/libavcodec/vlc.c +++ b/libavcodec/vlc.c @@ -499,7 +499,10 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC *single, for (int j = 0; j < 1<table[j].len; table[j].num = single->table[j].len > 0 ? 1 : 0; - AV_WN16(table[j].val, single->table[j].sym); + if (is16bit) + AV_WN16(table[j].val, single->table[j].sym); + else + table[j].val[0] = single->table[j].sym; } add_level(table, is16bit, nb_codes, numbits, buf, @@ -526,7 +529,7 @@ int ff_vlc_init_multi_from_lengths(VLC *vlc, VLC_MULTI *multi, int nb_bits, int multi->table = av_malloc(sizeof(*multi->table) << nb_bits); if (!multi->table) - return AVERROR(ENOMEM); + goto fail; j = code = 0; for (int i = 0; i < nb_codes; i++, lens += lens_wrap) { diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 89946135dc..96b0b66005 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -2007,8 +2007,7 @@ static int vp4_mc_loop_filter(Vp3DecodeContext *s, int plane, int motion_x, int x_offset = (-(x + 2) & 7) + 2; y_offset = (-(y + 2) & 7) + 2; - if (x_offset > 8 + x_subpel && y_offset > 8 + y_subpel) - return 0; + av_assert1(!(x_offset > 8 + x_subpel && y_offset > 8 + y_subpel)); s->vdsp.emulated_edge_mc(loop, motion_source - stride - 1, loop_stride, stride, diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index dd6c1b361b..faca7ecc1b 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -106,8 +106,11 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) if ((ret = ff_thread_get_ext_buffer(s->avctx, &f->tf, ref ? AV_GET_BUFFER_FLAG_REF : 0)) < 0) return ret; - if (!(f->seg_map = ff_refstruct_allocz(s->mb_width * s->mb_height))) + f->seg_map = ff_refstruct_allocz(s->mb_width * s->mb_height); + if (!f->seg_map) { + ret = AVERROR(ENOMEM); goto fail; + } ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private); if (ret < 0) goto fail; @@ -260,8 +263,16 @@ int update_dimensions(VP8Context *s, int width, int height, int is_vp7) return AVERROR(ENOMEM); } #if HAVE_THREADS - pthread_mutex_init(&s->thread_data[i].lock, NULL); - pthread_cond_init(&s->thread_data[i].cond, NULL); + ret = pthread_mutex_init(&s->thread_data[i].lock, NULL); + if (ret) { + free_buffers(s); + return AVERROR(ret); + } + ret = pthread_cond_init(&s->thread_data[i].cond, NULL); + if (ret) { + free_buffers(s); + return AVERROR(ret); + } #endif } @@ -354,9 +365,8 @@ static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size) } s->coeff_partition_size[i] = buf_size; - ff_vpx_init_range_decoder(&s->coeff_partition[i], buf, buf_size); - return 0; + return ff_vpx_init_range_decoder(&s->coeff_partition[i], buf, buf_size); } static void vp7_get_quants(VP8Context *s) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 855936cdc1..4cc5281303 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -717,6 +717,12 @@ static int decode_frame_header(AVCodecContext *avctx, s->s.h.segmentation.feat[i].skip_enabled = get_bits1(&s->gb); } } + } else { + // Reset fields under segmentation switch if segmentation is disabled. + // This is necessary because some hwaccels don't ignore these fields + // if segmentation is disabled. + s->s.h.segmentation.temporal = 0; + s->s.h.segmentation.update_map = 0; } // set qmul[] based on Y/UV, AC/DC and segmentation Q idx deltas diff --git a/libavcodec/vp9recon.c b/libavcodec/vp9recon.c index 073c04b47d..b8071f39b0 100644 --- a/libavcodec/vp9recon.c +++ b/libavcodec/vp9recon.c @@ -318,7 +318,11 @@ static av_always_inline void mc_luma_unscaled(VP9TileData *td, const vp9_mc_func // The arm/aarch64 _hv filters read one more row than what actually is // needed, so switch to emulated edge one pixel sooner vertically // (!!my * 5) than horizontally (!!mx * 4). + // The arm/aarch64 _h filters read one more pixel than what actually is + // needed, so switch to emulated edge if that would read beyond the bottom + // right block. if (x < !!mx * 3 || y < !!my * 3 || + ((ARCH_AARCH64 || ARCH_ARM) && (x + !!mx * 5 > w - bw) && (y + !!my * 5 + 1 > h - bh)) || x + !!mx * 4 > w - bw || y + !!my * 5 > h - bh) { s->vdsp.emulated_edge_mc(td->edge_emu_buffer, ref - !!my * 3 * ref_stride - !!mx * 3 * bytesperpixel, @@ -357,7 +361,11 @@ static av_always_inline void mc_chroma_unscaled(VP9TileData *td, const vp9_mc_fu // The arm/aarch64 _hv filters read one more row than what actually is // needed, so switch to emulated edge one pixel sooner vertically // (!!my * 5) than horizontally (!!mx * 4). + // The arm/aarch64 _h filters read one more pixel than what actually is + // needed, so switch to emulated edge if that would read beyond the bottom + // right block. if (x < !!mx * 3 || y < !!my * 3 || + ((ARCH_AARCH64 || ARCH_ARM) && (x + !!mx * 5 > w - bw) && (y + !!my * 5 + 1 > h - bh)) || x + !!mx * 4 > w - bw || y + !!my * 5 > h - bh) { s->vdsp.emulated_edge_mc(td->edge_emu_buffer, ref_u - !!my * 3 * src_stride_u - !!mx * 3 * bytesperpixel, diff --git a/libavcodec/vqcdec.c b/libavcodec/vqcdec.c index dc9248d99f..dbcaba7b23 100644 --- a/libavcodec/vqcdec.c +++ b/libavcodec/vqcdec.c @@ -146,10 +146,13 @@ static int decode_vectors(VqcContext * s, const uint8_t * buf, int size, int wid GetBitContext gb; uint8_t * vectors = s->vectors; uint8_t * vectors_end = s->vectors + (width * height * 3) / 2; + int ret; memset(vectors, 0, 3 * width * height / 2); - init_get_bits8(&gb, buf, size); + ret = init_get_bits8(&gb, buf, size); + if (ret < 0) + return ret; for (int i = 0; i < 3 * width * height / 2 / 32; i++) { uint8_t * dst = vectors; diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c index c9e398eaec..e607c1fc5f 100644 --- a/libavcodec/vulkan_av1.c +++ b/libavcodec/vulkan_av1.c @@ -76,7 +76,7 @@ static int vk_av1_fill_pict(AVCodecContext *avctx, const AV1Frame **ref_src, StdVideoDecodeAV1ReferenceInfo *vkav1_std_ref, VkVideoDecodeAV1DpbSlotInfoKHR *vkav1_ref, /* Goes in ^ */ const AV1Frame *pic, int is_current, int has_grain, - int *saved_order_hints) + const uint8_t *saved_order_hints) { FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; AV1VulkanDecodePicture *hp = pic->hwaccel_picture_private; @@ -97,9 +97,14 @@ static int vk_av1_fill_pict(AVCodecContext *avctx, const AV1Frame **ref_src, .RefFrameSignBias = hp->ref_frame_sign_bias_mask, }; - if (saved_order_hints) - for (int i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) - vkav1_std_ref->SavedOrderHints[i] = saved_order_hints[i]; + if (saved_order_hints) { + if (dec->quirk_av1_offset) + for (int i = 1; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++) + vkav1_std_ref->SavedOrderHints[i - 1] = saved_order_hints[i]; + else + for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++) + vkav1_std_ref->SavedOrderHints[i] = saved_order_hints[i]; + } *vkav1_ref = (VkVideoDecodeAV1DpbSlotInfoKHR) { .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_DPB_SLOT_INFO_KHR, @@ -242,7 +247,6 @@ static int vk_av1_start_frame(AVCodecContext *avctx, const AV1RawFrameHeader *frame_header = s->raw_frame_header; const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain; - CodedBitstreamAV1Context *cbs_ctx = (CodedBitstreamAV1Context *)(s->cbc->priv_data); const int apply_grain = !(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && film_grain->apply_grain; @@ -272,7 +276,7 @@ static int vk_av1_start_frame(AVCodecContext *avctx, ap->ref_frame_sign_bias_mask = 0x0; for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++) - ap->ref_frame_sign_bias_mask |= cbs_ctx->ref_frame_sign_bias[i] << i; + ap->ref_frame_sign_bias_mask |= pic->ref_frame_sign_bias[i] << i; for (int i = 0; i < STD_VIDEO_AV1_REFS_PER_FRAME; i++) { const int idx = pic->raw_frame_header->ref_frame_idx[i]; @@ -294,7 +298,7 @@ static int vk_av1_start_frame(AVCodecContext *avctx, err = vk_av1_fill_pict(avctx, &ap->ref_src[ref_count], &vp->ref_slots[ref_count], &vp->refs[ref_count], &ap->std_refs[ref_count], &ap->vkav1_refs[ref_count], - ref_frame, 0, 0, cbs_ctx->ref[idx].saved_order_hints); + ref_frame, 0, 0, ref_frame->order_hints); if (err < 0) return err; @@ -431,7 +435,7 @@ static int vk_av1_start_frame(AVCodecContext *avctx, .render_and_frame_size_different = frame_header->render_and_frame_size_different, .allow_screen_content_tools = frame_header->allow_screen_content_tools, .is_filter_switchable = frame_header->is_filter_switchable, - .force_integer_mv = frame_header->force_integer_mv, + .force_integer_mv = pic->force_integer_mv, .frame_size_override_flag = frame_header->frame_size_override_flag, .buffer_removal_time_present_flag = frame_header->buffer_removal_time_present_flag, .allow_intrabc = frame_header->allow_intrabc, @@ -491,8 +495,20 @@ static int vk_av1_start_frame(AVCodecContext *avctx, } } - for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++) + if (dec->quirk_av1_offset) + for (int i = 1; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++) + ap->std_pic_info.OrderHints[i - 1] = pic->order_hints[i]; + else + for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++) + ap->std_pic_info.OrderHints[i] = pic->order_hints[i]; + + for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++) { ap->loop_filter.loop_filter_ref_deltas[i] = frame_header->loop_filter_ref_deltas[i]; + ap->global_motion.GmType[i] = s->cur_frame.gm_type[i]; + for (int j = 0; j < STD_VIDEO_AV1_GLOBAL_MOTION_PARAMS; j++) { + ap->global_motion.gm_params[i][j] = s->cur_frame.gm_params[i][j]; + } + } for (int i = 0; i < STD_VIDEO_AV1_MAX_CDEF_FILTER_STRENGTHS; i++) { ap->cdef.cdef_y_pri_strength[i] = frame_header->cdef_y_pri_strength[i]; @@ -501,14 +517,6 @@ static int vk_av1_start_frame(AVCodecContext *avctx, ap->cdef.cdef_uv_sec_strength[i] = frame_header->cdef_uv_sec_strength[i]; } - for (int i = 0; i < STD_VIDEO_AV1_NUM_REF_FRAMES; i++) { - ap->std_pic_info.OrderHints[i] = frame_header->ref_order_hint[i]; - ap->global_motion.GmType[i] = s->cur_frame.gm_type[i]; - for (int j = 0; j < STD_VIDEO_AV1_GLOBAL_MOTION_PARAMS; j++) { - ap->global_motion.gm_params[i][j] = s->cur_frame.gm_params[i][j]; - } - } - if (apply_grain) { for (int i = 0; i < STD_VIDEO_AV1_MAX_NUM_Y_POINTS; i++) { ap->film_grain.point_y_value[i] = film_grain->point_y_value[i]; diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index 4561f26b62..5f6523920d 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -1114,6 +1114,7 @@ int ff_vk_decode_init(AVCodecContext *avctx) FFVulkanFunctions *vk; const VkVideoProfileInfoKHR *profile; const FFVulkanDecodeDescriptor *vk_desc; + const VkPhysicalDeviceDriverProperties *driver_props; VkVideoDecodeH264SessionParametersCreateInfoKHR h264_params = { .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_SESSION_PARAMETERS_CREATE_INFO_KHR, @@ -1275,6 +1276,14 @@ int ff_vk_decode_init(AVCodecContext *avctx) return AVERROR_EXTERNAL; } + driver_props = &dec->shared_ctx->s.driver_props; + if (driver_props->driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY && + driver_props->conformanceVersion.major == 1 && + driver_props->conformanceVersion.minor == 3 && + driver_props->conformanceVersion.subminor == 8 && + driver_props->conformanceVersion.patch < 3) + dec->quirk_av1_offset = 1; + ff_vk_decode_flush(avctx); av_log(avctx, AV_LOG_VERBOSE, "Vulkan decoder initialization sucessful\n"); diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h index 7ba8b239cb..076af93499 100644 --- a/libavcodec/vulkan_decode.h +++ b/libavcodec/vulkan_decode.h @@ -72,6 +72,10 @@ typedef struct FFVulkanDecodeContext { int external_fg; /* Oddity #2 - hardware can't apply film grain */ uint32_t frame_id_alloc_mask; /* For AV1 only */ + /* Workaround for NVIDIA drivers tested with CTS version 1.3.8 for AV1. + * The tests were incorrect as the OrderHints were offset by 1. */ + int quirk_av1_offset; + /* Thread-local state below */ struct HEVCHeaderSet *hevc_headers; size_t hevc_headers_size; diff --git a/libavcodec/vvc/vvc_ctu.c b/libavcodec/vvc/vvc_ctu.c index e48ffda938..ffd83e4ea0 100644 --- a/libavcodec/vvc/vvc_ctu.c +++ b/libavcodec/vvc/vvc_ctu.c @@ -1867,8 +1867,6 @@ static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, in cu->lfnst_idx = lfnst_idx_decode(lc); cu->mts_idx = mts_idx_decode(lc); set_qp_c(lc); - if (ret < 0) - return ret; } else { ret = skipped_transform_tree_unit(lc); if (ret < 0) diff --git a/libavcodec/vvc/vvc_mvs.c b/libavcodec/vvc/vvc_mvs.c index 6398fd3571..51d5e3b6b0 100644 --- a/libavcodec/vvc/vvc_mvs.c +++ b/libavcodec/vvc/vvc_mvs.c @@ -407,12 +407,11 @@ void ff_vvc_store_sb_mvs(const VVCLocalContext *lc, PredictionUnit *pu) const int sbw = cu->cb_width / mi->num_sb_x; const int sbh = cu->cb_height / mi->num_sb_y; SubblockParams params[2]; - MvField mvf; + MvField mvf = {0}; mvf.pred_flag = mi->pred_flag; mvf.bcw_idx = mi->bcw_idx; mvf.hpel_if_idx = mi->hpel_if_idx; - mvf.ciip_flag = 0; for (int i = 0; i < 2; i++) { const PredFlag mask = i + 1; if (mi->pred_flag & mask) { @@ -500,12 +499,11 @@ void ff_vvc_store_mvf(const VVCLocalContext *lc, const MvField *mvf) void ff_vvc_store_mv(const VVCLocalContext *lc, const MotionInfo *mi) { const CodingUnit *cu = lc->cu; - MvField mvf; + MvField mvf = {0}; mvf.hpel_if_idx = mi->hpel_if_idx; mvf.bcw_idx = mi->bcw_idx; mvf.pred_flag = mi->pred_flag; - mvf.ciip_flag = 0; for (int i = 0; i < 2; i++) { const PredFlag mask = i + 1; diff --git a/libavcodec/vvc/vvc_refs.c b/libavcodec/vvc/vvc_refs.c index afcfc09da7..893048454b 100644 --- a/libavcodec/vvc/vvc_refs.c +++ b/libavcodec/vvc/vvc_refs.c @@ -295,7 +295,7 @@ void ff_vvc_bump_frame(VVCContext *s, VVCFrameContext *fc) static VVCFrame *find_ref_idx(VVCContext *s, VVCFrameContext *fc, int poc, uint8_t use_msb) { - const int mask = use_msb ? ~0 : fc->ps.sps->max_pic_order_cnt_lsb - 1; + const unsigned mask = use_msb ? ~0 : fc->ps.sps->max_pic_order_cnt_lsb - 1; for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) { VVCFrame *ref = &fc->DPB[i]; @@ -454,7 +454,8 @@ int ff_vvc_slice_rpl(VVCContext *s, VVCFrameContext *fc, SliceContext *sc) if (ret < 0) return ret; } else { - avpriv_request_sample(fc->log_ctx, "Inter layer ref"); + // OPI_B_3.bit and VPS_A_3.bit should cover this + avpriv_report_missing_feature(fc->log_ctx, "Inter layer ref"); ret = AVERROR_PATCHWELCOME; return ret; } diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c index d5704aca25..ccb1b59862 100644 --- a/libavcodec/vvc/vvcdec.c +++ b/libavcodec/vvc/vvcdec.c @@ -476,13 +476,14 @@ static int slices_realloc(VVCFrameContext *fc) return 0; } -static void ep_init_cabac_decoder(SliceContext *sc, const int index, +static int ep_init_cabac_decoder(SliceContext *sc, const int index, const H2645NAL *nal, GetBitContext *gb, const CodedBitstreamUnit *unit) { const H266RawSlice *slice = unit->content_ref; const H266RawSliceHeader *rsh = sc->sh.r; EntryPoint *ep = sc->eps + index; int size; + int ret; if (index < rsh->num_entry_points) { int skipped = 0; @@ -499,8 +500,11 @@ static void ep_init_cabac_decoder(SliceContext *sc, const int index, } else { size = get_bits_left(gb) / 8; } - ff_init_cabac_decoder (&ep->cc, gb->buffer + get_bits_count(gb) / 8, size); + ret = ff_init_cabac_decoder (&ep->cc, gb->buffer + get_bits_count(gb) / 8, size); + if (ret < 0) + return ret; skip_bits(gb, size * 8); + return 0; } static int slice_init_entry_points(SliceContext *sc, @@ -511,6 +515,7 @@ static int slice_init_entry_points(SliceContext *sc, int nb_eps = sh->r->num_entry_points + 1; int ctu_addr = 0; GetBitContext gb; + int ret; if (sc->nb_eps != nb_eps) { eps_free(sc); @@ -520,7 +525,9 @@ static int slice_init_entry_points(SliceContext *sc, sc->nb_eps = nb_eps; } - init_get_bits8(&gb, slice->data, slice->data_size); + ret = init_get_bits8(&gb, slice->data, slice->data_size); + if (ret < 0) + return ret; for (int i = 0; i < sc->nb_eps; i++) { EntryPoint *ep = sc->eps + i; @@ -533,7 +540,9 @@ static int slice_init_entry_points(SliceContext *sc, fc->tab.slice_idx[rs] = sc->slice_idx; } - ep_init_cabac_decoder(sc, i, nal, &gb, unit); + ret = ep_init_cabac_decoder(sc, i, nal, &gb, unit); + if (ret < 0) + return ret; if (i + 1 < sc->nb_eps) ctu_addr = sh->entry_point_start_ctu[i]; @@ -782,6 +791,12 @@ static int decode_nal_unit(VVCContext *s, VVCFrameContext *fc, const H2645NAL *n s->temporal_id = nal->temporal_id; + if (nal->nuh_layer_id > 0) { + avpriv_report_missing_feature(fc->log_ctx, + "Decoding of multilayer bitstreams"); + return AVERROR_PATCHWELCOME; + } + switch (unit->type) { case VVC_VPS_NUT: case VVC_SPS_NUT: @@ -816,7 +831,6 @@ static int decode_nal_units(VVCContext *s, VVCFrameContext *fc, AVPacket *avpkt) const CodedBitstreamH266Context *h266 = s->cbc->priv_data; CodedBitstreamFragment *frame = &s->current_frame; int ret = 0; - int eos_at_start = 1; s->last_eos = s->eos; s->eos = 0; @@ -832,10 +846,7 @@ static int decode_nal_units(VVCContext *s, VVCFrameContext *fc, AVPacket *avpkt) const CodedBitstreamUnit *unit = frame->units + i; if (unit->type == VVC_EOB_NUT || unit->type == VVC_EOS_NUT) { - if (eos_at_start) - s->last_eos = 1; - else - s->eos = 1; + s->last_eos = 1; } else { ret = decode_nal_unit(s, fc, nal, unit); if (ret < 0) { @@ -939,6 +950,9 @@ static int vvc_decode_frame(AVCodecContext *avctx, AVFrame *output, if (ret < 0) return ret; + if (!fc->ft) + return avpkt->size; + ret = submit_frame(s, fc, output, got_output); if (ret < 0) return ret; diff --git a/libavcodec/wavarc.c b/libavcodec/wavarc.c index aa1af6330b..536c74e478 100644 --- a/libavcodec/wavarc.c +++ b/libavcodec/wavarc.c @@ -648,7 +648,7 @@ static int decode_5elp(AVCodecContext *avctx, for (int o = 0; o < order; o++) sum += s->filter[ch][o] * (unsigned)samples[n + 70 - o - 1]; - samples[n + 70] += ac_out[n] + (sum >> 4); + samples[n + 70] += ac_out[n] + (unsigned)(sum >> 4); } for (int n = 0; n < 70; n++) @@ -690,7 +690,7 @@ static int decode_5elp(AVCodecContext *avctx, for (int o = 0; o < order; o++) sum += s->filter[ch][o] * (unsigned)samples[n + 70 - o - 1]; - samples[n + 70] += ac_out[n] + (sum >> 4); + samples[n + 70] += ac_out[n] + (unsigned)(sum >> 4); } for (int n = 0; n < 70; n++) diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index 09b8731465..505bd3c96a 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -973,9 +973,11 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, static av_cold int wv_alloc_frame_context(WavpackContext *c) { - c->fdec = av_realloc_f(c->fdec, c->fdec_num + 1, sizeof(*c->fdec)); - if (!c->fdec) + WavpackFrameContext **fdec = av_realloc_array(c->fdec, c->fdec_num + 1, sizeof(*c->fdec)); + + if (!fdec) return -1; + c->fdec = fdec; c->fdec[c->fdec_num] = av_mallocz(sizeof(**c->fdec)); if (!c->fdec[c->fdec_num]) @@ -1095,11 +1097,6 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no, } s = wc->fdec[block_no]; - if (!s) { - av_log(avctx, AV_LOG_ERROR, "Context for block %d is not present\n", - block_no); - return AVERROR_INVALIDDATA; - } memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr)); memset(s->ch, 0, sizeof(s->ch)); diff --git a/libavcodec/wavpackenc.c b/libavcodec/wavpackenc.c index 33a5dfcc89..923eae55fc 100644 --- a/libavcodec/wavpackenc.c +++ b/libavcodec/wavpackenc.c @@ -1978,7 +1978,7 @@ static void encode_flush(WavPackEncodeContext *s) put_bits(pb, 31, 0x7FFFFFFF); cbits -= 31; } else { - put_bits(pb, cbits, (1 << cbits) - 1); + put_bits(pb, cbits, (1U << cbits) - 1); cbits = 0; } } while (cbits); @@ -2007,7 +2007,7 @@ static void encode_flush(WavPackEncodeContext *s) put_bits(pb, 31, 0x7FFFFFFF); cbits -= 31; } else { - put_bits(pb, cbits, (1 << cbits) - 1); + put_bits(pb, cbits, (1U << cbits) - 1); cbits = 0; } } while (cbits); diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 9308ea2b69..37ed134ed6 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -703,6 +703,9 @@ static int decode_entropy_coded_image(WebPContext *s, enum ImageRole role, ref_x = FFMAX(0, ref_x); ref_y = FFMAX(0, ref_y); + if (ref_y == y && ref_x >= x) + return AVERROR_INVALIDDATA; + /* copy pixels * source and dest regions can overlap and wrap lines, so just * copy per-pixel */ diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index 4e93aadab2..9bda7c7539 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -1505,6 +1505,8 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx, /* Parse frame type ("frame header"), see frame_descs */ int bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc, 6, 3)], block_nsamples; + pitch[0] = INT_MAX; + if (bd_idx < 0) { av_log(ctx, AV_LOG_ERROR, "Invalid frame type VLC code, skipping\n"); @@ -1622,6 +1624,9 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx, double i_lsps[MAX_LSPS]; float lpcs[MAX_LSPS]; + if(frame_descs[bd_idx].fcb_type >= FCB_TYPE_AW_PULSES && pitch[0] == INT_MAX) + return AVERROR_INVALIDDATA; + for (n = 0; n < s->lsps; n++) // LSF -> LSP i_lsps[n] = cos(0.5 * (prev_lsps[n] + lsps[n])); ff_acelp_lspd2lpc(i_lsps, lpcs, s->lsps >> 1); diff --git a/libavcodec/x86/vp3dsp_init.c b/libavcodec/x86/vp3dsp_init.c index f54fa57b3e..edac1764cb 100644 --- a/libavcodec/x86/vp3dsp_init.c +++ b/libavcodec/x86/vp3dsp_init.c @@ -53,7 +53,7 @@ av_cold void ff_vp3dsp_init_x86(VP3DSPContext *c, int flags) if (!(flags & AV_CODEC_FLAG_BITEXACT)) { c->v_loop_filter = c->v_loop_filter_unaligned = ff_vp3_v_loop_filter_mmxext; - c->h_loop_filter = c->v_loop_filter_unaligned = ff_vp3_h_loop_filter_mmxext; + c->h_loop_filter = c->h_loop_filter_unaligned = ff_vp3_h_loop_filter_mmxext; } } diff --git a/libavcodec/xan.c b/libavcodec/xan.c index cc0ecea5eb..56675dbbb1 100644 --- a/libavcodec/xan.c +++ b/libavcodec/xan.c @@ -607,6 +607,9 @@ static int xan_decode_frame(AVCodecContext *avctx, AVFrame *frame, return AVERROR_INVALIDDATA; } + if (buf_size < 9) + return AVERROR_INVALIDDATA; + if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) return ret; diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c index f86b7c58e7..b804a90298 100644 --- a/libavcodec/xsubdec.c +++ b/libavcodec/xsubdec.c @@ -59,6 +59,7 @@ static int decode_frame(AVCodecContext *avctx, AVSubtitle *sub, int64_t packet_time = 0; GetBitContext gb; int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A'); + int64_t start_display_time, end_display_time; // check that at least header fits if (buf_size < 27 + 7 * 2 + 4 * (3 + has_alpha)) { @@ -73,8 +74,14 @@ static int decode_frame(AVCodecContext *avctx, AVSubtitle *sub, } if (avpkt->pts != AV_NOPTS_VALUE) packet_time = av_rescale_q(avpkt->pts, AV_TIME_BASE_Q, (AVRational){1, 1000}); - sub->start_display_time = parse_timecode(buf + 1, packet_time); - sub->end_display_time = parse_timecode(buf + 14, packet_time); + + sub->start_display_time = start_display_time = parse_timecode(buf + 1, packet_time); + sub->end_display_time = end_display_time = parse_timecode(buf + 14, packet_time); + if (sub->start_display_time != start_display_time || + sub-> end_display_time != end_display_time) { + av_log(avctx, AV_LOG_ERROR, "time code not representable in 32bit\n"); + return -1; + } buf += 27; // read header diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m index d9b17ccdae..3fe3df2cb7 100644 --- a/libavdevice/avfoundation.m +++ b/libavdevice/avfoundation.m @@ -787,6 +787,9 @@ static NSArray* getDevicesWithMediaType(AVMediaType mediaType) { #endif #if (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 170000 || (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000)) [deviceTypes addObject: AVCaptureDeviceTypeContinuityCamera]; + [deviceTypes addObject: AVCaptureDeviceTypeExternal]; + #elif (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 140000) + [deviceTypes addObject: AVCaptureDeviceTypeExternalUnknown]; #endif } else if (mediaType == AVMediaTypeAudio) { #if (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 170000 || (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000)) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 0330d1d0b6..84db151577 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -432,8 +432,8 @@ dshow_get_device_media_types(AVFormatContext *avctx, enum dshowDeviceType devtyp IEnumMediaTypes_Release(types); if (p) IKsPropertySet_Release(p); - if (pin) - IPin_Release(pin); + + IPin_Release(pin); } IEnumPins_Release(pins); @@ -645,7 +645,7 @@ static int dshow_get_device_list(AVFormatContext *avctx, AVDeviceInfoList *devic } ret = dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, NULL, &device_list); - if (ret < S_OK) + if (ret < S_OK && ret != AVERROR(EIO)) goto error; ret = dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, NULL, &device_list); @@ -898,8 +898,8 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, if (devtype == VideoDevice) { VIDEO_STREAM_CONFIG_CAPS *vcaps = caps; - BITMAPINFOHEADER *bih; - int64_t *fr; + BITMAPINFOHEADER *bih = NULL; + int64_t *fr = NULL; #if DSHOWDEBUG ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps); #endif @@ -1001,7 +1001,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, " ch=%2u, bits=%2u, rate=%6lu\n", fx->nChannels, fx->wBitsPerSample, fx->nSamplesPerSec ); - continue; + goto next; } if ( (requested_sample_rate && requested_sample_rate != fx->nSamplesPerSec) || @@ -1370,10 +1370,10 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, goto error; } } - if (ctx->device_filter[otherDevType]) { + if (ctx->device_filter[otherDevType]) { // avoid adding add two instances of the same device to the graph, one for video, one for audio // a few devices don't support this (could also do this check earlier to avoid double crossbars, etc. but they seem OK) - if (strcmp(device_filter_unique_name, ctx->device_unique_name[otherDevType]) == 0) { + if (!device_filter_unique_name || strcmp(device_filter_unique_name, ctx->device_unique_name[otherDevType]) == 0) { av_log(avctx, AV_LOG_DEBUG, "reusing previous graph capture filter... %s\n", device_filter_unique_name); IBaseFilter_Release(device_filter); device_filter = ctx->device_filter[otherDevType]; @@ -1465,7 +1465,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, av_log(avctx, AV_LOG_ERROR, "Could not create CaptureGraphBuilder2\n"); goto error; } - ICaptureGraphBuilder2_SetFiltergraph(graph_builder2, graph); + r = ICaptureGraphBuilder2_SetFiltergraph(graph_builder2, graph); if (r != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not set graph for CaptureGraphBuilder2\n"); goto error; @@ -1546,7 +1546,10 @@ dshow_add_device(AVFormatContext *avctx, ctx->capture_filter[devtype]->stream_index = st->index; - ff_dshow_pin_ConnectionMediaType(ctx->capture_pin[devtype], &type); + if (ff_dshow_pin_ConnectionMediaType(ctx->capture_pin[devtype], &type) != S_OK) { + ret = AVERROR(EIO); + goto error; + } fmt_info = dshow_get_format_info(&type); if (!fmt_info) { ret = AVERROR(EIO); diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index 81e684b9be..bb39d4947a 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -124,14 +124,15 @@ void ff_dshow_##prefix##_Destroy(class *this) \ class *ff_dshow_##prefix##_Create(__VA_ARGS__) \ { \ class *this = CoTaskMemAlloc(sizeof(class)); \ - void *vtbl = CoTaskMemAlloc(sizeof(*this->vtbl)); \ dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_Create(%p)\n", this); \ - if (!this || !vtbl) \ + if (!this) \ goto fail; \ ZeroMemory(this, sizeof(class)); \ - ZeroMemory(vtbl, sizeof(*this->vtbl)); \ + this->vtbl = CoTaskMemAlloc(sizeof(*this->vtbl)); \ + if (!this->vtbl) \ + goto fail; \ + ZeroMemory(this->vtbl, sizeof(*this->vtbl)); \ this->ref = 1; \ - this->vtbl = vtbl; \ if (!setup) \ goto fail; \ dshowdebug("created ff_dshow_"AV_STRINGIFY(prefix)" %p\n", this); \ diff --git a/libavdevice/dshow_filter.c b/libavdevice/dshow_filter.c index 4642ac077c..2122c84626 100644 --- a/libavdevice/dshow_filter.c +++ b/libavdevice/dshow_filter.c @@ -135,7 +135,7 @@ long WINAPI ff_dshow_filter_JoinFilterGraph(DShowFilter *this, IFilterGraph *gra this->info.pGraph = graph; if (name) - wcscpy(this->info.achName, name); + wcscpy_s(this->info.achName, sizeof(this->info.achName) / sizeof(wchar_t), name); return S_OK; } diff --git a/libavdevice/pulse_audio_enc.c b/libavdevice/pulse_audio_enc.c index 3e2cc91f69..80136d1e20 100644 --- a/libavdevice/pulse_audio_enc.c +++ b/libavdevice/pulse_audio_enc.c @@ -471,10 +471,11 @@ static av_cold int pulse_write_header(AVFormatContext *h) s->nonblocking = (h->flags & AVFMT_FLAG_NONBLOCK); if (s->buffer_duration) { - int64_t bytes = s->buffer_duration; - bytes *= st->codecpar->ch_layout.nb_channels * st->codecpar->sample_rate * - av_get_bytes_per_sample(st->codecpar->format); - bytes /= 1000; + int64_t bytes = av_rescale(s->buffer_duration, + st->codecpar->ch_layout.nb_channels * + (int64_t)st->codecpar->sample_rate * + av_get_bytes_per_sample(st->codecpar->format), + 1000); buffer_attributes.tlength = FFMAX(s->buffer_size, av_clip64(bytes, 0, UINT32_MAX - 1)); av_log(s, AV_LOG_DEBUG, "Buffer duration: %ums recalculated into %"PRId64" bytes buffer.\n", diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 51291246b3..ee01711122 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -107,10 +107,10 @@ struct video_data { int (*open_f)(const char *file, int oflag, ...); int (*close_f)(int fd); int (*dup_f)(int fd); -#ifdef __GLIBC__ - int (*ioctl_f)(int fd, unsigned long int request, ...); -#else +#if HAVE_POSIX_IOCTL int (*ioctl_f)(int fd, int request, ...); +#else + int (*ioctl_f)(int fd, unsigned long int request, ...); #endif ssize_t (*read_f)(int fd, void *buffer, size_t n); void *(*mmap_f)(void *start, size_t length, int prot, int flags, int fd, int64_t offset); diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c index b2ff1f9828..329e79bf3f 100644 --- a/libavdevice/xcbgrab.c +++ b/libavdevice/xcbgrab.c @@ -827,7 +827,10 @@ static av_cold int xcbgrab_read_header(AVFormatContext *s) if (!sscanf(s->url, "%[^+]+%d,%d", display_name, &c->x, &c->y)) { *display_name = 0; - sscanf(s->url, "+%d,%d", &c->x, &c->y); + if(sscanf(s->url, "+%d,%d", &c->x, &c->y) != 2) { + if (*s->url) + av_log(s, AV_LOG_WARNING, "Ambigous URL: %s\n", s->url); + } } c->conn = xcb_connect(display_name[0] ? display_name : NULL, &screen_num); diff --git a/libavfilter/af_aderivative.c b/libavfilter/af_aderivative.c index eeaa23ff88..4883972dcf 100644 --- a/libavfilter/af_aderivative.c +++ b/libavfilter/af_aderivative.c @@ -126,6 +126,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) s->prev = ff_get_audio_buffer(inlink, 1); if (!s->prev) { av_frame_free(&in); + av_frame_free(&out); return AVERROR(ENOMEM); } } diff --git a/libavfilter/af_afftdn.c b/libavfilter/af_afftdn.c index b3ee6a4222..5c8712daf0 100644 --- a/libavfilter/af_afftdn.c +++ b/libavfilter/af_afftdn.c @@ -20,6 +20,7 @@ #include +#include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/channel_layout.h" #include "libavutil/opt.h" @@ -375,6 +376,8 @@ static void process_frame(AVFilterContext *ctx, case AV_SAMPLE_FMT_DBLP: noisy_data[i] = mag = hypot(fft_data_dbl[i].re, fft_data_dbl[i].im); break; + default: + av_assert2(0); } power = mag * mag; @@ -969,6 +972,8 @@ static void sample_noise_block(AudioFFTDeNoiseContext *s, mag2 = fft_out_dbl[n].re * fft_out_dbl[n].re + fft_out_dbl[n].im * fft_out_dbl[n].im; break; + default: + av_assert2(0); } mag2 = fmax(mag2, s->sample_floor); diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c index 6e54a7239d..9df9c28c7b 100644 --- a/libavfilter/af_afir.c +++ b/libavfilter/af_afir.c @@ -25,6 +25,7 @@ #include +#include "libavutil/avassert.h" #include "libavutil/cpu.h" #include "libavutil/tx.h" #include "libavutil/avstring.h" @@ -154,6 +155,8 @@ static int init_segment(AVFilterContext *ctx, AudioFIRSegment *seg, int selir, iscale.d = 1.0 / sqrt(2.0 * part_size); tx_type = AV_TX_DOUBLE_RDFT; break; + default: + av_assert1(0); } for (int ch = 0; ch < ctx->inputs[0]->ch_layout.nb_channels && part_size >= 1; ch++) { diff --git a/libavfilter/af_amerge.c b/libavfilter/af_amerge.c index 5daf639e74..26040e5ed5 100644 --- a/libavfilter/af_amerge.c +++ b/libavfilter/af_amerge.c @@ -245,8 +245,11 @@ static int try_push_frame(AVFilterContext *ctx, int nb_samples) av_make_q(1, outlink->sample_rate), outlink->time_base); - if ((ret = av_channel_layout_copy(&outbuf->ch_layout, &outlink->ch_layout)) < 0) + if ((ret = av_channel_layout_copy(&outbuf->ch_layout, &outlink->ch_layout)) < 0) { + free_frames(s->nb_inputs, inbuf); + av_frame_free(&outbuf); return ret; + } while (nb_samples) { /* Unroll the most common sample formats: speed +~350% for the loop, diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c index d6bd77beb3..8ff2fe5973 100644 --- a/libavfilter/af_aresample.c +++ b/libavfilter/af_aresample.c @@ -195,8 +195,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) av_frame_copy_props(outsamplesref, insamplesref); outsamplesref->format = outlink->format; ret = av_channel_layout_copy(&outsamplesref->ch_layout, &outlink->ch_layout); - if (ret < 0) + if (ret < 0) { + av_frame_free(&outsamplesref); + av_frame_free(&insamplesref); return ret; + } outsamplesref->sample_rate = outlink->sample_rate; if(insamplesref->pts != AV_NOPTS_VALUE) { diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c index f026c74494..92e605e1bf 100644 --- a/libavfilter/af_channelsplit.c +++ b/libavfilter/af_channelsplit.c @@ -22,7 +22,7 @@ * * Split an audio stream into per-channel streams. */ - +#include "libavutil/avassert.h" #include "libavutil/attributes.h" #include "libavutil/channel_layout.h" #include "libavutil/internal.h" @@ -156,6 +156,8 @@ static int filter_frame(AVFilterLink *outlink, AVFrame *buf) enum AVChannel channel = av_channel_layout_channel_from_index(&buf->ch_layout, s->map[i]); int ret; + av_assert1(channel >= 0); + AVFrame *buf_out = av_frame_clone(buf); if (!buf_out) return AVERROR(ENOMEM); diff --git a/libavfilter/af_mcompand.c b/libavfilter/af_mcompand.c index 1267cd9f34..9347f06d87 100644 --- a/libavfilter/af_mcompand.c +++ b/libavfilter/af_mcompand.c @@ -417,8 +417,8 @@ static int config_output(AVFilterLink *outlink) } new_nb_items += sscanf(tstr2, "%lf", &s->bands[i].topfreq) == 1; - if (s->bands[i].topfreq < 0 || s->bands[i].topfreq >= outlink->sample_rate / 2) { - av_log(ctx, AV_LOG_ERROR, "crossover_frequency: %f, should be >=0 and lower than half of sample rate: %d.\n", s->bands[i].topfreq, outlink->sample_rate / 2); + if (s->bands[i].topfreq < 0 || s->bands[i].topfreq >= outlink->sample_rate / 2.0) { + av_log(ctx, AV_LOG_ERROR, "crossover_frequency: %f, should be >=0 and lower than half of sample rate: %f.\n", s->bands[i].topfreq, outlink->sample_rate / 2.0); return AVERROR(EINVAL); } diff --git a/libavfilter/af_pan.c b/libavfilter/af_pan.c index 34073203d2..c806105a56 100644 --- a/libavfilter/af_pan.c +++ b/libavfilter/af_pan.c @@ -118,6 +118,14 @@ static av_cold int init(AVFilterContext *ctx) if (ret < 0) goto fail; + if (pan->nb_output_channels > MAX_CHANNELS) { + av_log(ctx, AV_LOG_ERROR, + "af_pan supports a maximum of %d channels. " + "Feel free to ask for a higher limit.\n", MAX_CHANNELS); + ret = AVERROR_PATCHWELCOME; + goto fail; + } + /* parse channel specifications */ while ((arg = arg0 = av_strtok(NULL, "|", &tokenizer))) { int used_in_ch[MAX_CHANNELS] = {0}; @@ -165,7 +173,7 @@ static av_cold int init(AVFilterContext *ctx) sign = 1; while (1) { gain = 1; - if (sscanf(arg, "%lf%n *%n", &gain, &len, &len)) + if (sscanf(arg, "%lf%n *%n", &gain, &len, &len) >= 1) arg += len; if (parse_channel_name(&arg, &in_ch_id, &named)){ av_log(ctx, AV_LOG_ERROR, diff --git a/libavfilter/af_surround.c b/libavfilter/af_surround.c index 5957860283..03e878c3cc 100644 --- a/libavfilter/af_surround.c +++ b/libavfilter/af_surround.c @@ -1122,6 +1122,31 @@ static av_cold int init(AVFilterContext *ctx) s->create_lfe = av_channel_layout_index_from_channel(&s->out_ch_layout, AV_CHAN_LOW_FREQUENCY) >= 0; + switch (out_channel_layout) { + case AV_CH_LAYOUT_MONO: + case AV_CH_LAYOUT_STEREO: + case AV_CH_LAYOUT_2POINT1: + case AV_CH_LAYOUT_2_1: + case AV_CH_LAYOUT_2_2: + case AV_CH_LAYOUT_SURROUND: + case AV_CH_LAYOUT_3POINT1: + case AV_CH_LAYOUT_QUAD: + case AV_CH_LAYOUT_4POINT0: + case AV_CH_LAYOUT_4POINT1: + case AV_CH_LAYOUT_5POINT0: + case AV_CH_LAYOUT_5POINT1: + case AV_CH_LAYOUT_5POINT0_BACK: + case AV_CH_LAYOUT_5POINT1_BACK: + case AV_CH_LAYOUT_6POINT0: + case AV_CH_LAYOUT_6POINT1: + case AV_CH_LAYOUT_7POINT0: + case AV_CH_LAYOUT_7POINT1: + case AV_CH_LAYOUT_OCTAGONAL: + break; + default: + goto fail; + } + switch (in_channel_layout) { case AV_CH_LAYOUT_STEREO: s->filter = filter_stereo; diff --git a/libavfilter/avf_showcwt.c b/libavfilter/avf_showcwt.c index 9436881f2a..c498f0a7bf 100644 --- a/libavfilter/avf_showcwt.c +++ b/libavfilter/avf_showcwt.c @@ -1029,6 +1029,8 @@ static int config_output(AVFilterLink *outlink) s->auto_frame_rate = av_make_q(inlink->sample_rate, s->hop_size); if (strcmp(s->rate_str, "auto")) { ret = av_parse_video_rate(&s->frame_rate, s->rate_str); + if (ret < 0) + return ret; } else { s->frame_rate = s->auto_frame_rate; } diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index bb5399c55e..f0a4e6fb66 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -794,6 +794,10 @@ static int reduce_formats_on_filter(AVFilterContext *filter) nb_formats, ff_add_format); REDUCE_FORMATS(int, AVFilterFormats, samplerates, formats, nb_formats, ff_add_format); + REDUCE_FORMATS(int, AVFilterFormats, color_spaces, formats, + nb_formats, ff_add_format); + REDUCE_FORMATS(int, AVFilterFormats, color_ranges, formats, + nb_formats, ff_add_format); /* reduce channel layouts */ for (i = 0; i < filter->nb_inputs; i++) { @@ -906,82 +910,6 @@ static void swap_samplerates(AVFilterGraph *graph) swap_samplerates_on_filter(graph->filters[i]); } -static void swap_color_spaces_on_filter(AVFilterContext *filter) -{ - AVFilterLink *link = NULL; - enum AVColorSpace csp; - int i; - - for (i = 0; i < filter->nb_inputs; i++) { - link = filter->inputs[i]; - if (link->type == AVMEDIA_TYPE_VIDEO && - link->outcfg.color_spaces->nb_formats == 1) - break; - } - if (i == filter->nb_inputs) - return; - - csp = link->outcfg.color_spaces->formats[0]; - - for (i = 0; i < filter->nb_outputs; i++) { - AVFilterLink *outlink = filter->outputs[i]; - if (outlink->type != AVMEDIA_TYPE_VIDEO) - continue; - /* there is no meaningful 'score' between different yuv matrices, - * so just prioritize an exact match if it exists */ - for (int j = 0; j < outlink->incfg.color_spaces->nb_formats; j++) { - if (csp == outlink->incfg.color_spaces->formats[j]) { - FFSWAP(int, outlink->incfg.color_spaces->formats[0], - outlink->incfg.color_spaces->formats[j]); - break; - } - } - } -} - -static void swap_color_spaces(AVFilterGraph *graph) -{ - for (int i = 0; i < graph->nb_filters; i++) - swap_color_spaces_on_filter(graph->filters[i]); -} - -static void swap_color_ranges_on_filter(AVFilterContext *filter) -{ - AVFilterLink *link = NULL; - enum AVColorRange range; - int i; - - for (i = 0; i < filter->nb_inputs; i++) { - link = filter->inputs[i]; - if (link->type == AVMEDIA_TYPE_VIDEO && - link->outcfg.color_ranges->nb_formats == 1) - break; - } - if (i == filter->nb_inputs) - return; - - range = link->outcfg.color_ranges->formats[0]; - - for (i = 0; i < filter->nb_outputs; i++) { - AVFilterLink *outlink = filter->outputs[i]; - if (outlink->type != AVMEDIA_TYPE_VIDEO) - continue; - for (int j = 0; j < outlink->incfg.color_ranges->nb_formats; j++) { - if (range == outlink->incfg.color_ranges->formats[j]) { - FFSWAP(int, outlink->incfg.color_ranges->formats[0], - outlink->incfg.color_ranges->formats[j]); - break; - } - } - } -} - -static void swap_color_ranges(AVFilterGraph *graph) -{ - for (int i = 0; i < graph->nb_filters; i++) - swap_color_ranges_on_filter(graph->filters[i]); -} - #define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER) #define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT) #define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT) @@ -1086,8 +1014,8 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter) } /* no penalty for LFE channel mismatch */ - if (av_channel_layout_channel_from_index(&in_chlayout, AV_CHAN_LOW_FREQUENCY) >= 0 && - av_channel_layout_channel_from_index(&out_chlayout, AV_CHAN_LOW_FREQUENCY) >= 0) + if (av_channel_layout_index_from_channel(&in_chlayout, AV_CHAN_LOW_FREQUENCY) >= 0 && + av_channel_layout_index_from_channel(&out_chlayout, AV_CHAN_LOW_FREQUENCY) >= 0) score += 10; av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(&in_chlayout, ~AV_CH_LOW_FREQUENCY)); av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~AV_CH_LOW_FREQUENCY)); @@ -1258,10 +1186,6 @@ static int graph_config_formats(AVFilterGraph *graph, void *log_ctx) if ((ret = reduce_formats(graph)) < 0) return ret; - /* for video filters, ensure that the best colorspace metadata is selected */ - swap_color_spaces(graph); - swap_color_ranges(graph); - /* for audio filters, ensure the best format, sample rate and channel layout * is selected */ swap_sample_fmts(graph); @@ -1486,7 +1410,7 @@ int avfilter_graph_request_oldest(AVFilterGraph *graph) if (r == AVERROR(EAGAIN) && !oldest->frame_wanted_out && !oldesti->frame_blocked_in && !oldesti->status_in) - ff_request_frame(oldest); + (void)ff_request_frame(oldest); else if (r < 0) return r; } diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index ddcd403785..fcae4f8e69 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -507,7 +507,7 @@ static int config_props(AVFilterLink *link) } break; case AVMEDIA_TYPE_AUDIO: - if (!c->ch_layout.nb_channels) { + if (!c->ch_layout.nb_channels || c->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) { int ret = av_channel_layout_copy(&c->ch_layout, &link->ch_layout); if (ret < 0) return ret; diff --git a/libavfilter/drawutils.c b/libavfilter/drawutils.c index 1081938d86..95525d38b4 100644 --- a/libavfilter/drawutils.c +++ b/libavfilter/drawutils.c @@ -61,6 +61,7 @@ int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt) had0 |= pos == 0; rgba_map[i] = pos; + depthb = db; } if (desc->nb_components == 3) diff --git a/libavfilter/f_loop.c b/libavfilter/f_loop.c index 0b08a2ead3..3936d1c1b0 100644 --- a/libavfilter/f_loop.c +++ b/libavfilter/f_loop.c @@ -21,6 +21,7 @@ #include "config_components.h" #include "libavutil/audio_fifo.h" +#include "libavutil/avassert.h" #include "libavutil/internal.h" #include "libavutil/opt.h" #include "avfilter.h" @@ -104,7 +105,7 @@ static av_cold void auninit(AVFilterContext *ctx) av_audio_fifo_free(s->left); } -static int push_samples(AVFilterContext *ctx, int nb_samples) +static int push_samples(AVFilterContext *ctx, int nb_samples, AVFrame **frame) { AVFilterLink *outlink = ctx->outputs[0]; LoopContext *s = ctx->priv; @@ -126,9 +127,7 @@ static int push_samples(AVFilterContext *ctx, int nb_samples) i += out->nb_samples; s->current_sample += out->nb_samples; - ret = ff_filter_frame(outlink, out); - if (ret < 0) - return ret; + *frame = out; if (s->current_sample >= s->nb_samples) { s->current_sample = 0; @@ -136,6 +135,8 @@ static int push_samples(AVFilterContext *ctx, int nb_samples) if (s->loop > 0) s->loop--; } + + return 0; } return ret; @@ -169,23 +170,19 @@ static int afilter_frame(AVFilterLink *inlink, AVFrame *frame) s->pts += av_rescale_q(s->start - s->ignored_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); } s->nb_samples += ret - drain; - drain = frame->nb_samples - written; - if (s->nb_samples == s->size && drain > 0) { + if (s->nb_samples == s->size && frame->nb_samples > written) { int ret2; ret2 = av_audio_fifo_write(s->left, (void **)frame->extended_data, frame->nb_samples); if (ret2 < 0) return ret2; - av_audio_fifo_drain(s->left, drain); + av_audio_fifo_drain(s->left, written); } frame->nb_samples = ret; s->pts += av_rescale_q(ret, (AVRational){1, outlink->sample_rate}, outlink->time_base); ret = ff_filter_frame(outlink, frame); } else { - int nb_samples = frame->nb_samples; - - av_frame_free(&frame); - ret = push_samples(ctx, nb_samples); + av_assert0(0); } } else { s->ignored_samples += frame->nb_samples; @@ -197,7 +194,7 @@ static int afilter_frame(AVFilterLink *inlink, AVFrame *frame) return ret; } -static int arequest_frame(AVFilterLink *outlink) +static int arequest_frame(AVFilterLink *outlink, AVFrame **frame) { AVFilterContext *ctx = outlink->src; LoopContext *s = ctx->priv; @@ -217,17 +214,11 @@ static int arequest_frame(AVFilterLink *outlink) av_audio_fifo_read(s->left, (void **)out->extended_data, nb_samples); out->pts = s->pts; s->pts += av_rescale_q(nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); - ret = ff_filter_frame(outlink, out); - if (ret < 0) - return ret; + *frame = out; } - ret = ff_request_frame(ctx->inputs[0]); + return 0; } else { - ret = push_samples(ctx, 1024); - } - - if (s->eof && s->nb_samples > 0 && s->loop != 0) { - ret = push_samples(ctx, 1024); + ret = push_samples(ctx, 1024, frame); } return ret; @@ -245,37 +236,31 @@ static int aactivate(AVFilterContext *ctx) update_time(ctx, inlink->time_base); - if (!s->eof && (s->nb_samples < s->size || !s->loop || !s->size)) { - const int in_nb_samples = FFMIN(1024, s->size - s->nb_samples); - if (in_nb_samples == 0) - ret = ff_inlink_consume_frame(inlink, &frame); - else - ret = ff_inlink_consume_samples(inlink, in_nb_samples, in_nb_samples, &frame); - if (ret < 0) - return ret; - if (ret > 0) - return afilter_frame(inlink, frame); - } +retry: + ret = arequest_frame(outlink, &frame); + if (ret < 0) + return ret; + if (frame) + return ff_filter_frame(outlink, frame); - if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &s->eof_pts)) { - if (status == AVERROR_EOF) { + ret = ff_inlink_consume_frame(inlink, &frame); + if (ret < 0) + return ret; + if (ret > 0) + return afilter_frame(inlink, frame); + + ret = ff_inlink_acknowledge_status(inlink, &status, &s->eof_pts); + if (ret) { + if (status == AVERROR_EOF && !s->eof) { s->size = s->nb_samples; s->eof = 1; + goto retry; } - } - - if (s->eof && (!s->loop || !s->size)) { - ff_outlink_set_status(outlink, AVERROR_EOF, s->eof_pts + s->pts_offset); + ff_outlink_set_status(outlink, status, s->eof_pts); return 0; } - if (!s->eof && (!s->size || - (s->nb_samples < s->size) || - (s->nb_samples >= s->size && s->loop == 0))) { - FF_FILTER_FORWARD_WANTED(outlink, inlink); - } else if (s->loop && s->nb_samples == s->size) { - return arequest_frame(outlink); - } + FF_FILTER_FORWARD_WANTED(outlink, inlink); return FFERROR_NOT_READY; } diff --git a/libavfilter/scale_eval.c b/libavfilter/scale_eval.c index 75ed503f15..dc8d522b1e 100644 --- a/libavfilter/scale_eval.c +++ b/libavfilter/scale_eval.c @@ -114,7 +114,7 @@ int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by) { - int w, h; + int64_t w, h; int factor_w, factor_h; w = *ret_w; @@ -149,9 +149,9 @@ int ff_scale_adjust_dimensions(AVFilterLink *inlink, * unless force_divisible_by is defined as well */ if (force_original_aspect_ratio) { // Including force_divisible_by here rounds to the nearest multiple of it. - int tmp_w = av_rescale(h, inlink->w, inlink->h * (int64_t)force_divisible_by) + int64_t tmp_w = av_rescale(h, inlink->w, inlink->h * (int64_t)force_divisible_by) * force_divisible_by; - int tmp_h = av_rescale(w, inlink->h, inlink->w * (int64_t)force_divisible_by) + int64_t tmp_h = av_rescale(w, inlink->h, inlink->w * (int64_t)force_divisible_by) * force_divisible_by; if (force_original_aspect_ratio == 1) { @@ -173,6 +173,9 @@ int ff_scale_adjust_dimensions(AVFilterLink *inlink, } } + if ((int32_t)w != w || (int32_t)h != h) + return AVERROR(EINVAL); + *ret_w = w; *ret_h = h; diff --git a/libavfilter/scale_eval.h b/libavfilter/scale_eval.h index 2eb6970aad..b489528404 100644 --- a/libavfilter/scale_eval.h +++ b/libavfilter/scale_eval.h @@ -41,7 +41,7 @@ int ff_scale_eval_dimensions(void *ctx, * force_original_aspect_ratio is set. force_divisible_by is used only when * force_original_aspect_ratio is set and must be at least 1. * - * Returns 0. + * Returns negative error code on error or non negative on success */ int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c index 88a8d6af86..60cf2b642e 100644 --- a/libavfilter/setpts.c +++ b/libavfilter/setpts.c @@ -150,6 +150,13 @@ static int config_input(AVFilterLink *inlink) return 0; } +static int config_output_video(AVFilterLink *outlink) +{ + outlink->frame_rate = (AVRational){ 1, 0 }; + + return 0; +} + #define BUF_SIZE 64 static inline char *double2int64str(char *buf, double v) @@ -198,6 +205,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) d = eval_pts(setpts, inlink, frame, frame->pts); frame->pts = D2TS(d); + frame->duration = 0; av_log(inlink->dst, AV_LOG_TRACE, "N:%"PRId64" PTS:%s T:%f", @@ -322,6 +330,14 @@ static const AVFilterPad avfilter_vf_setpts_inputs[] = { }, }; +static const AVFilterPad outputs_video[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_output_video, + }, +}; + const AVFilter ff_vf_setpts = { .name = "setpts", .description = NULL_IF_CONFIG_SMALL("Set PTS for the output video frame."), @@ -335,7 +351,7 @@ const AVFilter ff_vf_setpts = { .priv_class = &setpts_class, FILTER_INPUTS(avfilter_vf_setpts_inputs), - FILTER_OUTPUTS(ff_video_default_filterpad), + FILTER_OUTPUTS(outputs_video), }; #endif /* CONFIG_SETPTS_FILTER */ diff --git a/libavfilter/signature_lookup.c b/libavfilter/signature_lookup.c index 9c69c02fbf..ad59106cf0 100644 --- a/libavfilter/signature_lookup.c +++ b/libavfilter/signature_lookup.c @@ -447,14 +447,14 @@ static MatchingInfo evaluate_parameters(AVFilterContext *ctx, SignatureContext * } if (tolerancecount > 2) { - a = aprev; - b = bprev; if (dir == DIR_NEXT) { /* turn around */ a = infos->first; b = infos->second; dir = DIR_PREV; } else { + a = aprev; + b = bprev; break; } } @@ -495,10 +495,10 @@ static MatchingInfo evaluate_parameters(AVFilterContext *ctx, SignatureContext * continue; /* matching sequence is too short */ if ((double) goodfcount / (double) fcount < sc->thit) continue; - if ((double) goodfcount*0.5 < FFMAX(gooda, goodb)) + if ((double) goodfcount*0.5 <= FFMAX(gooda, goodb)) continue; - meandist = (double) goodfcount / (double) distsum; + meandist = (double) distsum / (double) goodfcount; if (meandist < minmeandist || status == (STATUS_END_REACHED | STATUS_BEGIN_REACHED) || diff --git a/libavfilter/vf_addroi.c b/libavfilter/vf_addroi.c index e7ad916214..24efd62d5d 100644 --- a/libavfilter/vf_addroi.c +++ b/libavfilter/vf_addroi.c @@ -39,6 +39,7 @@ enum { static const char *const addroi_var_names[] = { "iw", "ih", + NULL, }; typedef struct AddROIContext { diff --git a/libavfilter/vf_avgblur.c b/libavfilter/vf_avgblur.c index 8ff6111bcc..d1ce029b5c 100644 --- a/libavfilter/vf_avgblur.c +++ b/libavfilter/vf_avgblur.c @@ -287,7 +287,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) const int width = s->planewidth[plane]; if (!(s->planes & (1 << plane))) { - if (out != in) + if (out->data[plane] != in->data[plane]) av_image_copy_plane(out->data[plane], out->linesize[plane], in->data[plane], in->linesize[plane], width * ((s->depth + 7) / 8), height); diff --git a/libavfilter/vf_bm3d.c b/libavfilter/vf_bm3d.c index 17d39ee7cf..11d373c643 100644 --- a/libavfilter/vf_bm3d.c +++ b/libavfilter/vf_bm3d.c @@ -273,7 +273,7 @@ static void do_block_matching_multi(BM3DContext *s, const uint8_t *src, int src_ int r_y, int r_x, int plane, int jobnr) { SliceContext *sc = &s->slices[jobnr]; - double MSE2SSE = s->group_size * s->block_size * s->block_size * src_range * src_range / (s->max * s->max); + double MSE2SSE = s->group_size * s->block_size * s->block_size * src_range * src_range / (double)(s->max * s->max); double distMul = 1. / MSE2SSE; double th_sse = th_mse * MSE2SSE; int index = sc->nb_match_blocks; diff --git a/libavfilter/vf_convolution_opencl.c b/libavfilter/vf_convolution_opencl.c index 0eff9f40d3..40938436f2 100644 --- a/libavfilter/vf_convolution_opencl.c +++ b/libavfilter/vf_convolution_opencl.c @@ -20,6 +20,7 @@ #include "config_components.h" +#include "libavutil/avassert.h" #include "libavutil/common.h" #include "libavutil/imgutils.h" #include "libavutil/mem.h" @@ -80,6 +81,8 @@ static int convolution_opencl_init(AVFilterContext *avctx) kernel_name = "prewitt_global"; } else if (!strcmp(avctx->filter->name, "roberts_opencl")){ kernel_name = "roberts_global"; + } else { + av_assert0(0); } ctx->kernel = clCreateKernel(ctx->ocf.program, kernel_name, &cle); CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to create " diff --git a/libavfilter/vf_deshake_opencl.c b/libavfilter/vf_deshake_opencl.c index e49c808a8e..128545a982 100644 --- a/libavfilter/vf_deshake_opencl.c +++ b/libavfilter/vf_deshake_opencl.c @@ -703,7 +703,7 @@ static int minimize_error( total_err += deshake_ctx->ransac_err[j]; } - if (total_err < best_err) { + if (i == 0 || total_err < best_err) { for (int mi = 0; mi < 6; ++mi) { best_model[mi] = model[mi]; } diff --git a/libavfilter/vf_elbg.c b/libavfilter/vf_elbg.c index 17947e226a..863366ccc2 100644 --- a/libavfilter/vf_elbg.c +++ b/libavfilter/vf_elbg.c @@ -194,7 +194,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) p0 = (uint8_t *)out->data[0]; for (i = 0; i < elbg->codebook_length; i++) { - const int al = elbg->use_alpha ? elbg->codebook[i*4+3] : 0xff; + const unsigned al = elbg->use_alpha ? elbg->codebook[i*4+3] : 0xff; pal[i] = al << 24 | (elbg->codebook[i*4+2] << 16) | (elbg->codebook[i*4+1] << 8) | diff --git a/libavfilter/vf_grayworld.c b/libavfilter/vf_grayworld.c index e9c959416e..236e3d4417 100644 --- a/libavfilter/vf_grayworld.c +++ b/libavfilter/vf_grayworld.c @@ -275,10 +275,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } /* input and output transfer will be linear */ if (in->color_trc == AVCOL_TRC_UNSPECIFIED) { - av_log(s, AV_LOG_WARNING, "Untagged transfer, assuming linear light.\n"); + av_log(ctx, AV_LOG_WARNING, "Untagged transfer, assuming linear light.\n"); out->color_trc = AVCOL_TRC_LINEAR; } else if (in->color_trc != AVCOL_TRC_LINEAR) { - av_log(s, AV_LOG_WARNING, "Gray world color correction works on linear light only.\n"); + av_log(ctx, AV_LOG_WARNING, "Gray world color correction works on linear light only.\n"); } td.in = in; diff --git a/libavfilter/vf_lut3d.c b/libavfilter/vf_lut3d.c index a312ca76c9..a03fdb33ae 100644 --- a/libavfilter/vf_lut3d.c +++ b/libavfilter/vf_lut3d.c @@ -702,7 +702,8 @@ try_again: else if (!strncmp(line + 7, "MAX ", 4)) vals = max; if (!vals) return AVERROR_INVALIDDATA; - av_sscanf(line + 11, "%f %f %f", vals, vals + 1, vals + 2); + if (av_sscanf(line + 11, "%f %f %f", vals, vals + 1, vals + 2) != 3) + return AVERROR_INVALIDDATA; av_log(ctx, AV_LOG_DEBUG, "min: %f %f %f | max: %f %f %f\n", min[0], min[1], min[2], max[0], max[1], max[2]); goto try_again; @@ -1733,12 +1734,14 @@ try_again: else if (!strncmp(line + 7, "MAX ", 4)) vals = max; if (!vals) return AVERROR_INVALIDDATA; - av_sscanf(line + 11, "%f %f %f", vals, vals + 1, vals + 2); + if (av_sscanf(line + 11, "%f %f %f", vals, vals + 1, vals + 2) != 3) + return AVERROR_INVALIDDATA; av_log(ctx, AV_LOG_DEBUG, "min: %f %f %f | max: %f %f %f\n", min[0], min[1], min[2], max[0], max[1], max[2]); goto try_again; } else if (!strncmp(line, "LUT_1D_INPUT_RANGE ", 19)) { - av_sscanf(line + 19, "%f %f", min, max); + if (av_sscanf(line + 19, "%f %f", min, max) != 2) + return AVERROR_INVALIDDATA; min[1] = min[2] = min[0]; max[1] = max[2] = max[0]; goto try_again; diff --git a/libavfilter/vf_premultiply.c b/libavfilter/vf_premultiply.c index e077d46a9a..5e97c2000f 100644 --- a/libavfilter/vf_premultiply.c +++ b/libavfilter/vf_premultiply.c @@ -36,8 +36,8 @@ typedef struct ThreadData { typedef struct PreMultiplyContext { const AVClass *class; - int width[4], height[4]; - int linesize[4]; + int width[AV_VIDEO_MAX_PLANES], height[AV_VIDEO_MAX_PLANES]; + int linesize[AV_VIDEO_MAX_PLANES]; int nb_planes; int planes; int inverse; @@ -45,7 +45,7 @@ typedef struct PreMultiplyContext { int half, depth, offset, max; FFFrameSync fs; - void (*premultiply[4])(const uint8_t *msrc, const uint8_t *asrc, + void (*premultiply[AV_VIDEO_MAX_PLANES])(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, diff --git a/libavfilter/vf_rotate.c b/libavfilter/vf_rotate.c index 3adde22c09..3e65f26552 100644 --- a/libavfilter/vf_rotate.c +++ b/libavfilter/vf_rotate.c @@ -288,7 +288,9 @@ static int config_props(AVFilterLink *outlink) double res; char *expr; - ff_draw_init2(&rot->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); + ret = ff_draw_init2(&rot->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); + if (ret < 0) + return ret; ff_draw_color(&rot->draw, &rot->color, rot->fillcolor); rot->hsub = pixdesc->log2_chroma_w; diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index fc3b5a91e6..960ce42b54 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -551,10 +551,13 @@ static int config_props(AVFilterLink *outlink) outlink->w = scale->w; outlink->h = scale->h; - ff_scale_adjust_dimensions(inlink, &outlink->w, &outlink->h, + ret = ff_scale_adjust_dimensions(inlink, &outlink->w, &outlink->h, scale->force_original_aspect_ratio, scale->force_divisible_by); + if (ret < 0) + goto fail; + if (outlink->w > INT_MAX || outlink->h > INT_MAX || (outlink->h * inlink->w) > INT_MAX || diff --git a/libavfilter/vf_signature.c b/libavfilter/vf_signature.c index 758b6e5101..3858fe3070 100644 --- a/libavfilter/vf_signature.c +++ b/libavfilter/vf_signature.c @@ -379,6 +379,9 @@ static int xml_export(AVFilterContext *ctx, StreamContext *sc, const char* filen FILE* f; unsigned int pot3[5] = { 3*3*3*3, 3*3*3, 3*3, 3, 1 }; + if (!sc->coarseend->last) + return AVERROR(EINVAL); // No frames ? + f = avpriv_fopen_utf8(filename, "w"); if (!f) { int err = AVERROR(EINVAL); diff --git a/libavfilter/vf_thumbnail_cuda.c b/libavfilter/vf_thumbnail_cuda.c index c8dd905123..40a3b75dd0 100644 --- a/libavfilter/vf_thumbnail_cuda.c +++ b/libavfilter/vf_thumbnail_cuda.c @@ -290,7 +290,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) hist[i] = 4 * hist[i]; } - CHECK_CU(cu->cuCtxPopCurrent(&dummy)); + ret = CHECK_CU(cu->cuCtxPopCurrent(&dummy)); if (ret < 0) return ret; diff --git a/libavfilter/vf_tiltandshift.c b/libavfilter/vf_tiltandshift.c index dc30f4ff1b..0149cd44d5 100644 --- a/libavfilter/vf_tiltandshift.c +++ b/libavfilter/vf_tiltandshift.c @@ -177,14 +177,14 @@ static void copy_column(AVFilterLink *outlink, const uint8_t *src[4]; dst[0] = dst_data[0] + ncol; - dst[1] = dst_data[1] + (ncol >> s->desc->log2_chroma_h); - dst[2] = dst_data[2] + (ncol >> s->desc->log2_chroma_h); + dst[1] = dst_data[1] + (ncol >> s->desc->log2_chroma_w); + dst[2] = dst_data[2] + (ncol >> s->desc->log2_chroma_w); if (!tilt) ncol = 0; src[0] = src_data[0] + ncol; - src[1] = src_data[1] + (ncol >> s->desc->log2_chroma_h); - src[2] = src_data[2] + (ncol >> s->desc->log2_chroma_h); + src[1] = src_data[1] + (ncol >> s->desc->log2_chroma_w); + src[2] = src_data[2] + (ncol >> s->desc->log2_chroma_w); av_image_copy(dst, dst_linesizes, src, src_linesizes, outlink->format, 1, outlink->h); } @@ -239,8 +239,10 @@ static int output_frame(AVFilterLink *outlink) // set correct timestamps and props as long as there is proper input ret = av_frame_copy_props(dst, s->input); - if (ret < 0) + if (ret < 0) { + av_frame_free(&dst); return ret; + } // discard frame at the top of the list since it has been fully processed list_remove_head(s); diff --git a/libavfilter/vf_tonemap_opencl.c b/libavfilter/vf_tonemap_opencl.c index a2a27307b4..03219857d4 100644 --- a/libavfilter/vf_tonemap_opencl.c +++ b/libavfilter/vf_tonemap_opencl.c @@ -343,8 +343,7 @@ static int tonemap_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input) int err; double peak = ctx->peak; - AVHWFramesContext *input_frames_ctx = - (AVHWFramesContext*)input->hw_frames_ctx->data; + AVHWFramesContext *input_frames_ctx; av_log(ctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u (%"PRId64").\n", av_get_pix_fmt_name(input->format), @@ -352,6 +351,7 @@ static int tonemap_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input) if (!input->hw_frames_ctx) return AVERROR(EINVAL); + input_frames_ctx = (AVHWFramesContext*)input->hw_frames_ctx->data; output = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!output) { diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c index 942b47d7a4..37aa4eb72f 100644 --- a/libavfilter/vf_v360.c +++ b/libavfilter/vf_v360.c @@ -3787,6 +3787,8 @@ static int barrelsplit_to_xyz(const V360Context *s, case 3: // back bottom vf = (y * 2.f - 1.5f) / scaleh + 3.f - facef; break; + default: + av_assert0(0); } l_x = (0.5f - uf) / scalew; l_y = 0.5f * dir_vert; @@ -4251,8 +4253,8 @@ static int v360_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) int16_t *u = r->u[p] + ((j - slice_start) * uv_linesize + i) * elements; int16_t *v = r->v[p] + ((j - slice_start) * uv_linesize + i) * elements; int16_t *ker = r->ker[p] + ((j - slice_start) * uv_linesize + i) * elements; - uint8_t *mask8 = p ? NULL : r->mask + ((j - slice_start) * s->pr_width[0] + i); - uint16_t *mask16 = p ? NULL : (uint16_t *)r->mask + ((j - slice_start) * s->pr_width[0] + i); + uint8_t *mask8 = (p || !r->mask) ? NULL : r->mask + ((j - slice_start) * s->pr_width[0] + i); + uint16_t *mask16 = (p || !r->mask) ? NULL : (uint16_t *)r->mask + ((j - slice_start) * s->pr_width[0] + i); int in_mask, out_mask; if (s->out_transpose) diff --git a/libavfilter/vf_xfade.c b/libavfilter/vf_xfade.c index 4eea761dac..e97117704a 100644 --- a/libavfilter/vf_xfade.c +++ b/libavfilter/vf_xfade.c @@ -956,7 +956,7 @@ static void vertopen##name##_transition(AVFilterContext *ctx, { \ XFadeContext *s = ctx->priv; \ const int width = out->width; \ - const float w2 = out->width / 2; \ + const float w2 = out->width / 2.0; \ \ for (int y = slice_start; y < slice_end; y++) { \ for (int x = 0; x < width; x++) { \ @@ -984,7 +984,7 @@ static void vertclose##name##_transition(AVFilterContext *ctx, XFadeContext *s = ctx->priv; \ const int nb_planes = s->nb_planes; \ const int width = out->width; \ - const float w2 = out->width / 2; \ + const float w2 = out->width / 2.0; \ \ for (int y = slice_start; y < slice_end; y++) { \ for (int x = 0; x < width; x++) { \ @@ -1012,7 +1012,7 @@ static void horzopen##name##_transition(AVFilterContext *ctx, XFadeContext *s = ctx->priv; \ const int nb_planes = s->nb_planes; \ const int width = out->width; \ - const float h2 = out->height / 2; \ + const float h2 = out->height / 2.0; \ \ for (int y = slice_start; y < slice_end; y++) { \ const float smooth = 2.f - fabsf((y - h2) / h2) - progress * 2.f; \ @@ -1040,7 +1040,7 @@ static void horzclose##name##_transition(AVFilterContext *ctx, XFadeContext *s = ctx->priv; \ const int nb_planes = s->nb_planes; \ const int width = out->width; \ - const float h2 = out->height / 2; \ + const float h2 = out->height / 2.0; \ \ for (int y = slice_start; y < slice_end; y++) { \ const float smooth = 1.f + fabsf((y - h2) / h2) - progress * 2.f; \ @@ -2288,8 +2288,11 @@ static int xfade_activate(AVFilterContext *avctx) // Check if we are not yet transitioning, in which case // just request and forward the input frame. if (s->start_pts > s->pts) { + int ret; s->passthrough = 1; - ff_inlink_consume_frame(in_a, &s->xf[0]); + ret = ff_inlink_consume_frame(in_a, &s->xf[0]); + if (ret < 0) + return ret; return ff_filter_frame(outlink, s->xf[0]); } s->passthrough = 0; @@ -2297,8 +2300,14 @@ static int xfade_activate(AVFilterContext *avctx) // We are transitioning, so we need a frame from second input if (ff_inlink_check_available_frame(in_b)) { int ret; - ff_inlink_consume_frame(avctx->inputs[0], &s->xf[0]); - ff_inlink_consume_frame(avctx->inputs[1], &s->xf[1]); + ret = ff_inlink_consume_frame(avctx->inputs[0], &s->xf[0]); + if (ret < 0) + return ret; + ret = ff_inlink_consume_frame(avctx->inputs[1], &s->xf[1]); + if (ret < 0) { + av_frame_free(&s->xf[0]); + return ret; + } // Calculate PTS offset to first input if (s->inputs_offset_pts == AV_NOPTS_VALUE) diff --git a/libavfilter/vf_xfade_opencl.c b/libavfilter/vf_xfade_opencl.c index 2368c046b4..8582230924 100644 --- a/libavfilter/vf_xfade_opencl.c +++ b/libavfilter/vf_xfade_opencl.c @@ -293,7 +293,9 @@ static int xfade_opencl_activate(AVFilterContext *avctx) if (ctx->first_pts + ctx->offset_pts > ctx->xf[0]->pts) { ctx->xf[0] = NULL; ctx->need_second = 0; - ff_inlink_consume_frame(avctx->inputs[0], &in); + ret = ff_inlink_consume_frame(avctx->inputs[0], &in); + if (ret < 0) + return ret; return ff_filter_frame(outlink, in); } @@ -302,8 +304,14 @@ static int xfade_opencl_activate(AVFilterContext *avctx) } if (ctx->xf[0] && ff_inlink_queued_frames(avctx->inputs[1]) > 0) { - ff_inlink_consume_frame(avctx->inputs[0], &ctx->xf[0]); - ff_inlink_consume_frame(avctx->inputs[1], &ctx->xf[1]); + ret = ff_inlink_consume_frame(avctx->inputs[0], &ctx->xf[0]); + if (ret < 0) + return ret; + ret = ff_inlink_consume_frame(avctx->inputs[1], &ctx->xf[1]); + if (ret < 0) { + av_frame_free(&ctx->xf[0]); + return ret; + } ctx->last_pts = ctx->xf[1]->pts; ctx->pts = ctx->xf[0]->pts; diff --git a/libavformat/Makefile b/libavformat/Makefile index 44aa485029..ae86954e7c 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -723,11 +723,12 @@ OBJS-$(CONFIG_LIBSSH_PROTOCOL) += libssh.o OBJS-$(CONFIG_LIBZMQ_PROTOCOL) += libzmq.o # Objects duplicated from other libraries for shared builds -SHLIBOBJS += log2_tab.o to_upper4.o +SHLIBOBJS += log2_tab.o to_upper4.o bitstream.o SHLIBOBJS-$(CONFIG_ISO_MEDIA) += mpegaudiotabs.o SHLIBOBJS-$(CONFIG_FLV_MUXER) += mpeg4audio_sample_rates.o SHLIBOBJS-$(CONFIG_HLS_DEMUXER) += ac3_channel_layout_tab.o SHLIBOBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER) += jpegxl_parse.o +SHLIBOBJS-$(CONFIG_JNI) += ffjni.o SHLIBOBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER) += jpegxl_parse.o SHLIBOBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio_sample_rates.o SHLIBOBJS-$(CONFIG_MOV_DEMUXER) += ac3_channel_layout_tab.o diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c index f647f557cc..dc6638de3a 100644 --- a/libavformat/ac4dec.c +++ b/libavformat/ac4dec.c @@ -43,6 +43,8 @@ static int ac4_probe(const AVProbeData *p) size += 4; if (buf[1] == 0x41) size += 2; + if (left < size) + break; max_frames++; left -= size; buf += size; diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index 9318943f96..fc01ffcbf1 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -106,6 +106,8 @@ static int get_aiff_header(AVFormatContext *s, int64_t size, size++; par->codec_type = AVMEDIA_TYPE_AUDIO; channels = avio_rb16(pb); + if (par->ch_layout.nb_channels && par->ch_layout.nb_channels != channels) + return AVERROR_INVALIDDATA; par->ch_layout.nb_channels = channels; num_frames = avio_rb32(pb); par->bits_per_coded_sample = avio_rb16(pb); diff --git a/libavformat/ape.c b/libavformat/ape.c index 231064be61..c664cd60fe 100644 --- a/libavformat/ape.c +++ b/libavformat/ape.c @@ -291,7 +291,7 @@ static int ape_read_header(AVFormatContext * s) final_size -= final_size & 3; } if (file_size <= 0 || final_size <= 0) - final_size = ape->finalframeblocks * 8; + final_size = ape->finalframeblocks * 8LL; ape->frames[ape->totalframes - 1].size = final_size; for (i = 0; i < ape->totalframes; i++) { diff --git a/libavformat/apetag.c b/libavformat/apetag.c index f2794c46f2..8316abc07c 100644 --- a/libavformat/apetag.c +++ b/libavformat/apetag.c @@ -120,7 +120,8 @@ int64_t ff_ape_parse_tag(AVFormatContext *s) avio_seek(pb, file_size - APE_TAG_FOOTER_BYTES, SEEK_SET); - avio_read(pb, buf, 8); /* APETAGEX */ + if(avio_read(pb, buf, 8) != 8) /* APETAGEX */ + return 0; if (strncmp(buf, APE_TAG_PREAMBLE, 8)) { return 0; } diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c index 61bfc6de1f..e08f029f80 100644 --- a/libavformat/argo_asf.c +++ b/libavformat/argo_asf.c @@ -259,7 +259,7 @@ static int argo_asf_seek(AVFormatContext *s, int stream_index, return -1; offset = asf->fhdr.chunk_offset + ASF_CHUNK_HEADER_SIZE + - (block * st->codecpar->block_align); + block * (int64_t)st->codecpar->block_align; if ((offset = avio_seek(s->pb, offset, SEEK_SET)) < 0) return offset; diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c index f88def3731..94b404b5d0 100644 --- a/libavformat/argo_brp.c +++ b/libavformat/argo_brp.c @@ -380,8 +380,8 @@ static int argo_brp_read_packet(AVFormatContext *s, AVPacket *pkt) if (blk.size < ASF_CHUNK_HEADER_SIZE) return AVERROR_INVALIDDATA; - if ((ret = avio_read(s->pb, buf, ASF_CHUNK_HEADER_SIZE)) < 0) - return ret; + if (avio_read(s->pb, buf, ASF_CHUNK_HEADER_SIZE) != ASF_CHUNK_HEADER_SIZE) + return AVERROR_INVALIDDATA; ff_argo_asf_parse_chunk_header(&ckhdr, buf); diff --git a/libavformat/asf.c b/libavformat/asf.c index 1285062220..2a5859ed68 100644 --- a/libavformat/asf.c +++ b/libavformat/asf.c @@ -89,8 +89,8 @@ static int asf_read_picture(AVFormatContext *s, int len) return 0; } - if (picsize >= len) { - av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n", + if (picsize >= len || ((int64_t)len - picsize) * 2 + 1 > INT_MAX) { + av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d (len = %d).\n", picsize, len); return AVERROR_INVALIDDATA; } diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index 9713c02b0a..8daae216a6 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -674,7 +674,7 @@ static int asf_read_marker(AVFormatContext *s) avio_rl64(pb); // offset, 8 bytes pres_time = avio_rl64(pb); // presentation time - pres_time = av_sat_sub64(pres_time, asf->hdr.preroll * 10000); + pres_time = av_sat_sub64(pres_time, asf->hdr.preroll * 10000LL); avio_rl16(pb); // entry length avio_rl32(pb); // send time avio_rl32(pb); // flags diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c index 484fb64b36..8ec1c80943 100644 --- a/libavformat/asfdec_o.c +++ b/libavformat/asfdec_o.c @@ -866,6 +866,9 @@ static int asf_read_simple_index(AVFormatContext *s, const GUIDParseTable *g) int64_t offset; uint64_t size = avio_rl64(pb); + if (size < 24) + return AVERROR_INVALIDDATA; + // simple index objects should be ordered by stream number, this loop tries to find // the first not indexed video stream for (i = 0; i < asf->nb_streams; i++) { diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c index 3363003b18..8c0b8fe975 100644 --- a/libavformat/av1dec.c +++ b/libavformat/av1dec.c @@ -379,6 +379,7 @@ static int obu_get_packet(AVFormatContext *s, AVPacket *pkt) if (size < 0) return size; + memset(header + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); len = read_obu_with_size(header, size, &obu_size, &type); if (len < 0) { av_log(c, AV_LOG_ERROR, "Failed to read obu\n"); diff --git a/libavformat/bintext.c b/libavformat/bintext.c index 90d48b6691..c96c14ccd9 100644 --- a/libavformat/bintext.c +++ b/libavformat/bintext.c @@ -93,9 +93,12 @@ static int next_tag_read(AVFormatContext *avctx, uint64_t *fsize) AVIOContext *pb = avctx->pb; char buf[36]; int len; - uint64_t start_pos = avio_size(pb) - 256; + int64_t start_pos = avio_size(pb); - avio_seek(pb, start_pos, SEEK_SET); + if (start_pos < 256) + return AVERROR_INVALIDDATA; + + avio_seek(pb, start_pos - 256, SEEK_SET); if (avio_read(pb, buf, sizeof(next_magic)) != sizeof(next_magic)) return -1; if (memcmp(buf, next_magic, sizeof(next_magic))) @@ -245,7 +248,10 @@ static int xbin_read_header(AVFormatContext *s) return AVERROR(EIO); if (pb->seekable & AVIO_SEEKABLE_NORMAL) { - bin->fsize = avio_size(pb) - 9 - st->codecpar->extradata_size; + int64_t fsize = avio_size(pb); + if (fsize < 9 + st->codecpar->extradata_size) + return 0; + bin->fsize = fsize - 9 - st->codecpar->extradata_size; ff_sauce_read(s, &bin->fsize, NULL, 0); avio_seek(pb, 9 + st->codecpar->extradata_size, SEEK_SET); } @@ -285,7 +291,10 @@ static int adf_read_header(AVFormatContext *s) if (pb->seekable & AVIO_SEEKABLE_NORMAL) { int got_width = 0; - bin->fsize = avio_size(pb) - 1 - 192 - 4096; + int64_t fsize = avio_size(pb); + if (fsize < 1 + 192 + 4096) + return 0; + bin->fsize = fsize - 1 - 192 - 4096; st->codecpar->width = 80<<3; ff_sauce_read(s, &bin->fsize, &got_width, 0); if (st->codecpar->width < 8) @@ -318,6 +327,7 @@ static int idf_read_header(AVFormatContext *s) AVIOContext *pb = s->pb; AVStream *st; int got_width = 0, ret; + int64_t fsize; if (!(pb->seekable & AVIO_SEEKABLE_NORMAL)) return AVERROR(EIO); @@ -332,14 +342,18 @@ static int idf_read_header(AVFormatContext *s) st->codecpar->extradata[0] = 16; st->codecpar->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; - avio_seek(pb, avio_size(pb) - 4096 - 48, SEEK_SET); + fsize = avio_size(pb); + if (fsize < 12 + 4096 + 48) + return AVERROR_INVALIDDATA; + bin->fsize = fsize - 12 - 4096 - 48; + + avio_seek(pb, bin->fsize + 12, SEEK_SET); if (avio_read(pb, st->codecpar->extradata + 2 + 48, 4096) < 0) return AVERROR(EIO); if (avio_read(pb, st->codecpar->extradata + 2, 48) < 0) return AVERROR(EIO); - bin->fsize = avio_size(pb) - 12 - 4096 - 48; ff_sauce_read(s, &bin->fsize, &got_width, 0); if (st->codecpar->width < 8) return AVERROR_INVALIDDATA; diff --git a/libavformat/bitstream.c b/libavformat/bitstream.c new file mode 100644 index 0000000000..2afda37c30 --- /dev/null +++ b/libavformat/bitstream.c @@ -0,0 +1 @@ +#include "libavcodec/bitstream.c" diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index b1d0de18f1..93cab01ce0 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -638,6 +638,11 @@ static int concat_parse_script(AVFormatContext *avf) } } + if (!file) { + ret = AVERROR_INVALIDDATA; + goto fail; + } + if (file->inpoint != AV_NOPTS_VALUE && file->outpoint != AV_NOPTS_VALUE) { if (file->inpoint > file->outpoint || file->outpoint - (uint64_t)file->inpoint > INT64_MAX) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 63070b77be..5909677bf1 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -445,7 +445,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, av_freep(pb); av_dict_copy(&tmp, *opts, 0); av_dict_copy(&tmp, opts2, 0); - ret = avio_open2(pb, url, AVIO_FLAG_READ, c->interrupt_callback, &tmp); + ret = ffio_open_whitelist(pb, url, AVIO_FLAG_READ, c->interrupt_callback, &tmp, s->protocol_whitelist, s->protocol_blacklist); if (ret >= 0) { // update cookies on http response with setcookies. char *new_cookies = NULL; @@ -1224,7 +1224,7 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in) close_in = 1; av_dict_copy(&opts, c->avio_opts, 0); - ret = avio_open2(&in, url, AVIO_FLAG_READ, c->interrupt_callback, &opts); + ret = ffio_open_whitelist(&in, url, AVIO_FLAG_READ, c->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist); av_dict_free(&opts); if (ret < 0) return ret; diff --git a/libavformat/demux.c b/libavformat/demux.c index 147f3b93ac..5027b84206 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -2499,7 +2499,7 @@ static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket * int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { FFFormatContext *const si = ffformatcontext(ic); - int count = 0, ret = 0; + int count = 0, ret = 0, err; int64_t read_size; AVPacket *pkt1 = si->pkt; int64_t old_offset = avio_tell(ic->pb); @@ -3010,9 +3010,11 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } } - ret = compute_chapters_end(ic); - if (ret < 0) + err = compute_chapters_end(ic); + if (err < 0) { + ret = err; goto find_stream_info_err; + } /* update the stream parameters from the internal codec contexts */ for (unsigned i = 0; i < ic->nb_streams; i++) { diff --git a/libavformat/dxa.c b/libavformat/dxa.c index 813e665a27..56b19a7fca 100644 --- a/libavformat/dxa.c +++ b/libavformat/dxa.c @@ -120,6 +120,8 @@ static int dxa_read_header(AVFormatContext *s) avio_skip(pb, fsize); } c->bpc = (fsize + (int64_t)c->frames - 1) / c->frames; + if (c->bpc < 0) + return AVERROR_INVALIDDATA; if(ast->codecpar->block_align) { if (c->bpc > INT_MAX - ast->codecpar->block_align + 1) return AVERROR_INVALIDDATA; diff --git a/libavformat/ffjni.c b/libavformat/ffjni.c new file mode 100644 index 0000000000..2b1483cf42 --- /dev/null +++ b/libavformat/ffjni.c @@ -0,0 +1,23 @@ +/* + * JNI utility functions - included stub + * + * Copyright (c) 2024 Leo Izen + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavcodec/ffjni.c" diff --git a/libavformat/file.c b/libavformat/file.c index 182995717a..1f853e0e17 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -527,8 +527,8 @@ const URLProtocol ff_fd_protocol = { #if CONFIG_ANDROID_CONTENT_PROTOCOL #include +#include "libavcodec/ffjni.h" #include "libavcodec/jni.h" -#include "libavcodec/ffjni.c" typedef struct JFields { jclass uri_class; diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 4ce6251137..5fe835cd05 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -282,12 +282,6 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde if (avio_seek(s->pb, *ppos, SEEK_SET) < 0) return AV_NOPTS_VALUE; - parser = av_parser_init(st->codecpar->codec_id); - if (!parser){ - return AV_NOPTS_VALUE; - } - parser->flags |= PARSER_FLAG_USE_CODEC_TS; - if (!flac->parser_dec) { flac->parser_dec = avcodec_alloc_context3(NULL); if (!flac->parser_dec) @@ -298,6 +292,11 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde return ret; } + parser = av_parser_init(st->codecpar->codec_id); + if (!parser) + return AV_NOPTS_VALUE; + parser->flags |= PARSER_FLAG_USE_CODEC_TS; + for (;;){ uint8_t *data; int size; diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 892371fcd0..725b5a0c89 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -1111,6 +1111,7 @@ static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, int64_t return TYPE_UNKNOWN; } + av_free(flv->metaVideoColor); if (!(flv->metaVideoColor = av_mallocz(sizeof(FLVMetaVideoColor)))) { return AVERROR(ENOMEM); } diff --git a/libavformat/fwse.c b/libavformat/fwse.c index 6c1103da14..dc4750d946 100644 --- a/libavformat/fwse.c +++ b/libavformat/fwse.c @@ -67,7 +67,7 @@ static int fwse_read_header(AVFormatContext *s) av_channel_layout_default(&par->ch_layout, channels); st->duration = avio_rl32(pb); par->sample_rate = avio_rl32(pb); - if (par->sample_rate <= 0 || par->sample_rate > INT_MAX) + if (par->sample_rate <= 0) return AVERROR_INVALIDDATA; par->block_align = 1; diff --git a/libavformat/hls.c b/libavformat/hls.c index 8702113e9f..274dc2b895 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -222,6 +222,7 @@ typedef struct HLSContext { AVDictionary *avio_opts; AVDictionary *seg_format_opts; char *allowed_extensions; + int extension_picky; int max_reload; int http_persistent; int http_multiple; @@ -730,6 +731,46 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, return ret; } +static int test_segment(AVFormatContext *s, const AVInputFormat *in_fmt, struct playlist *pls, struct segment *seg) +{ + HLSContext *c = s->priv_data; + int matchA = 3; + int matchF = 0; + + if (!c->extension_picky) + return 0; + + if (strcmp(c->allowed_extensions, "ALL")) + matchA = av_match_ext (seg->url, c->allowed_extensions) + + 2*(ff_match_url_ext(seg->url, c->allowed_extensions) > 0); + + if (!matchA) { + av_log(s, AV_LOG_ERROR, "URL %s is not in allowed_extensions\n", seg->url); + return AVERROR_INVALIDDATA; + } + + if (in_fmt) { + if (in_fmt->extensions) { + matchF = av_match_ext( seg->url, in_fmt->extensions) + + 2*(ff_match_url_ext(seg->url, in_fmt->extensions) > 0); + if(av_match_name("mp4", in_fmt->name)) { + matchF |= av_match_ext( seg->url, "ts,m2t,m2ts,mts,mpg,m4s,mpeg,mpegts") + + 2*(ff_match_url_ext(seg->url, "ts,m2t,m2ts,mts,mpg,m4s,mpeg,mpegts") > 0); + } + } else if (!strcmp(in_fmt->name, "mpegts")) { + matchF = av_match_ext( seg->url, "ts,m2t,m2ts,mts,mpg,m4s,mpeg,mpegts") + + 2*(ff_match_url_ext(seg->url, "ts,m2t,m2ts,mts,mpg,m4s,mpeg,mpegts") > 0); + } + + if (!(matchA & matchF)) { + av_log(s, AV_LOG_ERROR, "detected format %s extension %s mismatches allowed extensions in url %s\n", in_fmt->name, in_fmt->extensions ? in_fmt->extensions : "none", seg->url); + return AVERROR_INVALIDDATA; + } + } + + return 0; +} + static int parse_playlist(HLSContext *c, const char *url, struct playlist *pls, AVIOContext *in) { @@ -988,6 +1029,14 @@ static int parse_playlist(HLSContext *c, const char *url, goto fail; } + ret = test_segment(c->ctx, pls->ctx ? pls->ctx->iformat : NULL, pls, seg); + if (ret < 0) { + av_free(seg->url); + av_free(seg->key); + av_free(seg); + goto fail; + } + if (duration < 0.001 * AV_TIME_BASE) { av_log(c->ctx, AV_LOG_WARNING, "Cannot get correct #EXTINF value of segment %s," " set to default value to 1ms.\n", seg->url); @@ -2112,6 +2161,11 @@ static int hls_read_header(AVFormatContext *s) pls->ctx->interrupt_callback = s->interrupt_callback; url = av_strdup(pls->segments[0]->url); ret = av_probe_input_buffer(&pls->pb.pub, &in_fmt, url, NULL, 0, 0); + + for (int n = 0; n < pls->n_segments; n++) + if (ret >= 0) + ret = test_segment(s, in_fmt, pls, pls->segments[n]); + if (ret < 0) { /* Free the ctx - it isn't initialized properly at this point, * so avformat_close_input shouldn't be called. If @@ -2572,6 +2626,8 @@ static const AVOption hls_options[] = { OFFSET(allowed_extensions), AV_OPT_TYPE_STRING, {.str = "3gp,aac,avi,ac3,eac3,flac,mkv,m3u8,m4a,m4s,m4v,mpg,mov,mp2,mp3,mp4,mpeg,mpegts,ogg,ogv,oga,ts,vob,wav"}, INT_MIN, INT_MAX, FLAGS}, + {"extension_picky", "Be picky with all extensions matching", + OFFSET(extension_picky), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS}, {"max_reload", "Maximum number of times a insufficient list is attempted to be reloaded", OFFSET(max_reload), AV_OPT_TYPE_INT, {.i64 = 3}, 0, INT_MAX, FLAGS}, {"m3u8_hold_counters", "The maximum number of times to load m3u8 when it refreshes without new segments", diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 2202ce64e4..bf294549a9 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2427,7 +2427,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) int is_ref_pkt = 1; int ret = 0, can_split = 1, i, j; int stream_index = 0; - int subtitle_streams = 0; int range_length = 0; const char *proto = NULL; int use_temp_file = 0; @@ -2435,6 +2434,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) char *old_filename = NULL; for (i = 0; i < hls->nb_varstreams; i++) { + int subtitle_streams = 0; vs = &hls->var_streams[i]; for (j = 0; j < vs->nb_streams; j++) { if (vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { @@ -2601,8 +2601,10 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) " will retry with a new http session.\n"); ff_format_io_close(s, &vs->out); ret = hlsenc_io_open(s, &vs->out, filename, &options); - reflush_dynbuf(vs, &range_length); - ret = hlsenc_io_close(s, &vs->out, filename); + if (ret >= 0) { + reflush_dynbuf(vs, &range_length); + ret = hlsenc_io_close(s, &vs->out, filename); + } } av_dict_free(&options); av_freep(&vs->temp_buffer); @@ -2613,6 +2615,9 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) hls_rename_temp_file(s, oc); } + if (ret < 0) + return ret; + old_filename = av_strdup(oc->url); if (!old_filename) { return AVERROR(ENOMEM); diff --git a/libavformat/hnm.c b/libavformat/hnm.c index 42efaaa3e8..425dadc5e3 100644 --- a/libavformat/hnm.c +++ b/libavformat/hnm.c @@ -114,6 +114,8 @@ static int hnm_read_packet(AVFormatContext *s, AVPacket *pkt) if (hnm->superchunk_remaining == 0) { /* parse next superchunk */ superchunk_size = avio_rl24(pb); + if (superchunk_size < 4) + return AVERROR_INVALIDDATA; avio_skip(pb, 1); hnm->superchunk_remaining = superchunk_size - 4; @@ -124,7 +126,7 @@ static int hnm_read_packet(AVFormatContext *s, AVPacket *pkt) chunk_id = avio_rl16(pb); avio_skip(pb, 2); - if (chunk_size > hnm->superchunk_remaining || !chunk_size) { + if (chunk_size > hnm->superchunk_remaining || chunk_size < 8) { av_log(s, AV_LOG_ERROR, "invalid chunk size: %"PRIu32", offset: %"PRId64"\n", chunk_size, avio_tell(pb)); diff --git a/libavformat/iamf.h b/libavformat/iamf.h index 68f05c635b..fd8b57a096 100644 --- a/libavformat/iamf.h +++ b/libavformat/iamf.h @@ -68,7 +68,7 @@ typedef struct IAMFCodecConfig { enum AVCodecID codec_id; uint32_t codec_tag; unsigned nb_samples; - int seek_preroll; + int audio_roll_distance; int sample_rate; int extradata_size; uint8_t *extradata; diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c index cb49cf0a57..c1e9cbebaa 100644 --- a/libavformat/iamf_parse.c +++ b/libavformat/iamf_parse.c @@ -38,7 +38,7 @@ static int opus_decoder_config(IAMFCodecConfig *codec_config, { int left = len - avio_tell(pb); - if (left < 11) + if (left < 11 || codec_config->audio_roll_distance >= 0) return AVERROR_INVALIDDATA; codec_config->extradata = av_malloc(left + 8); @@ -64,7 +64,10 @@ static int aac_decoder_config(IAMFCodecConfig *codec_config, int object_type_id, codec_id, stream_type; int ret, tag, left; - tag = avio_r8(pb); + if (codec_config->audio_roll_distance >= 0) + return AVERROR_INVALIDDATA; + + ff_mp4_read_descr(logctx, pb, &tag); if (tag != MP4DecConfigDescrTag) return AVERROR_INVALIDDATA; @@ -84,21 +87,22 @@ static int aac_decoder_config(IAMFCodecConfig *codec_config, if (codec_id && codec_id != codec_config->codec_id) return AVERROR_INVALIDDATA; - tag = avio_r8(pb); - if (tag != MP4DecSpecificDescrTag) + left = ff_mp4_read_descr(logctx, pb, &tag); + if (tag != MP4DecSpecificDescrTag || + !left || left > (len - avio_tell(pb))) return AVERROR_INVALIDDATA; - left = len - avio_tell(pb); - if (left <= 0) - return AVERROR_INVALIDDATA; - - codec_config->extradata = av_malloc(left); + // We pad extradata here because avpriv_mpeg4audio_get_config2() needs it. + codec_config->extradata = av_malloc((size_t)left + AV_INPUT_BUFFER_PADDING_SIZE); if (!codec_config->extradata) return AVERROR(ENOMEM); - codec_config->extradata_size = avio_read(pb, codec_config->extradata, left); - if (codec_config->extradata_size < left) - return AVERROR_INVALIDDATA; + ret = ffio_read_size(pb, codec_config->extradata, left); + if (ret < 0) + return ret; + codec_config->extradata_size = left; + memset(codec_config->extradata + codec_config->extradata_size, 0, + AV_INPUT_BUFFER_PADDING_SIZE); ret = avpriv_mpeg4audio_get_config2(&cfg, codec_config->extradata, codec_config->extradata_size, 1, logctx); @@ -115,6 +119,9 @@ static int flac_decoder_config(IAMFCodecConfig *codec_config, { int left; + if (codec_config->audio_roll_distance) + return AVERROR_INVALIDDATA; + avio_skip(pb, 4); // METADATA_BLOCK_HEADER left = len - avio_tell(pb); @@ -143,7 +150,7 @@ static int ipcm_decoder_config(IAMFCodecConfig *codec_config, }; int sample_format = avio_r8(pb); // 0 = BE, 1 = LE int sample_size = (avio_r8(pb) / 8 - 2); // 16, 24, 32 - if (sample_format > 1 || sample_size > 2) + if (sample_format > 1 || sample_size > 2U || codec_config->audio_roll_distance) return AVERROR_INVALIDDATA; codec_config->codec_id = sample_fmt[sample_format][sample_size]; @@ -163,7 +170,7 @@ static int codec_config_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) uint8_t *buf; enum AVCodecID avcodec_id; unsigned codec_config_id, nb_samples, codec_id; - int16_t seek_preroll; + int16_t audio_roll_distance; int ret; buf = av_malloc(len); @@ -183,7 +190,7 @@ static int codec_config_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) codec_config_id = ffio_read_leb(pbc); codec_id = avio_rb32(pbc); nb_samples = ffio_read_leb(pbc); - seek_preroll = avio_rb16(pbc); + audio_roll_distance = avio_rb16(pbc); switch(codec_id) { case MKBETAG('O','p','u','s'): @@ -222,7 +229,7 @@ static int codec_config_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) codec_config->codec_config_id = codec_config_id; codec_config->codec_id = avcodec_id; codec_config->nb_samples = nb_samples; - codec_config->seek_preroll = seek_preroll; + codec_config->audio_roll_distance = audio_roll_distance; switch(codec_id) { case MKBETAG('O','p','u','s'): @@ -243,6 +250,12 @@ static int codec_config_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) if (ret < 0) goto fail; + if ((codec_config->nb_samples > INT_MAX) || codec_config->nb_samples <= 0 || + (-codec_config->audio_roll_distance > INT_MAX / codec_config->nb_samples)) { + ret = AVERROR_INVALIDDATA; + goto fail; + } + c->codec_configs[c->nb_codec_configs++] = codec_config; len -= avio_tell(pbc); @@ -269,6 +282,9 @@ static int update_extradata(AVCodecParameters *codecpar) switch(codecpar->codec_id) { case AV_CODEC_ID_OPUS: AV_WB8(codecpar->extradata + 9, codecpar->ch_layout.nb_channels); + AV_WL16(codecpar->extradata + 10, AV_RB16(codecpar->extradata + 10)); // Byte swap pre-skip + AV_WL32(codecpar->extradata + 12, AV_RB32(codecpar->extradata + 12)); // Byte swap sample rate + AV_WL16(codecpar->extradata + 16, AV_RB16(codecpar->extradata + 16)); // Byte swap Output Gain break; case AV_CODEC_ID_AAC: { uint8_t buf[5]; @@ -290,10 +306,10 @@ static int update_extradata(AVCodecParameters *codecpar) skip_bits(&gb, 4); put_bits(&pb, 4, codecpar->ch_layout.nb_channels); // set channel config ret = put_bits_left(&pb); - put_bits(&pb, ret, get_bits(&gb, ret)); + put_bits(&pb, ret, get_bits_long(&gb, ret)); flush_put_bits(&pb); - memcpy(codecpar->extradata, buf, sizeof(buf)); + memcpy(codecpar->extradata, buf, put_bytes_output(&pb)); break; } case AV_CODEC_ID_FLAC: { @@ -330,7 +346,7 @@ static int scalable_channel_layout_config(void *s, AVIOContext *pb, nb_layers = avio_r8(pb) >> 5; // get_bits(&gb, 3); // skip_bits(&gb, 5); //reserved - if (nb_layers > 6) + if (nb_layers > 6 || nb_layers == 0) return AVERROR_INVALIDDATA; audio_element->layers = av_calloc(nb_layers, sizeof(*audio_element->layers)); @@ -355,6 +371,9 @@ static int scalable_channel_layout_config(void *s, AVIOContext *pb, substream_count = avio_r8(pb); coupled_substream_count = avio_r8(pb); + if (substream_count + k > audio_element->nb_substreams) + return AVERROR_INVALIDDATA; + audio_element->layers[i].substream_count = substream_count; audio_element->layers[i].coupled_substream_count = coupled_substream_count; if (output_gain_is_present_flag) { @@ -396,11 +415,11 @@ static int ambisonics_config(void *s, AVIOContext *pb, ambisonics_mode = ffio_read_leb(pb); if (ambisonics_mode > 1) - return 0; + return AVERROR_INVALIDDATA; output_channel_count = avio_r8(pb); // C substream_count = avio_r8(pb); // N - if (audio_element->nb_substreams != substream_count) + if (audio_element->nb_substreams != substream_count || output_channel_count == 0) return AVERROR_INVALIDDATA; order = floor(sqrt(output_channel_count - 1)); @@ -479,6 +498,7 @@ static int param_parse(void *s, IAMFContext *c, AVIOContext *pb, AVIAMFParamDefinition *param; unsigned int parameter_id, parameter_rate, mode; unsigned int duration = 0, constant_subblock_duration = 0, nb_subblocks = 0; + unsigned int total_duration = 0; size_t param_size; parameter_id = ffio_read_leb(pb); @@ -499,8 +519,10 @@ static int param_parse(void *s, IAMFContext *c, AVIOContext *pb, constant_subblock_duration = ffio_read_leb(pb); if (constant_subblock_duration == 0) nb_subblocks = ffio_read_leb(pb); - else + else { nb_subblocks = duration / constant_subblock_duration; + total_duration = duration; + } } param = av_iamf_param_definition_alloc(type, nb_subblocks, ¶m_size); @@ -511,8 +533,11 @@ static int param_parse(void *s, IAMFContext *c, AVIOContext *pb, void *subblock = av_iamf_param_definition_get_subblock(param, i); unsigned int subblock_duration = constant_subblock_duration; - if (constant_subblock_duration == 0) + if (constant_subblock_duration == 0) { subblock_duration = ffio_read_leb(pb); + total_duration += subblock_duration; + } else if (i == nb_subblocks - 1) + subblock_duration = duration - i * constant_subblock_duration; switch (type) { case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN: { @@ -540,6 +565,12 @@ static int param_parse(void *s, IAMFContext *c, AVIOContext *pb, } } + if (!mode && !constant_subblock_duration && total_duration != duration) { + av_log(s, AV_LOG_ERROR, "Invalid subblock durations in parameter_id %u\n", parameter_id); + av_free(param); + return AVERROR_INVALIDDATA; + } + param->parameter_id = parameter_id; param->parameter_rate = parameter_rate; param->duration = duration; @@ -588,7 +619,7 @@ static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) FFIOContext b; AVIOContext *pbc; uint8_t *buf; - unsigned audio_element_id, codec_config_id, num_parameters; + unsigned audio_element_id, nb_substreams, codec_config_id, num_parameters; int audio_element_type, ret; buf = av_malloc(len); @@ -615,6 +646,12 @@ static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) } audio_element_type = avio_r8(pbc) >> 5; + if (audio_element_type > AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE) { + av_log(s, AV_LOG_DEBUG, "Unknown audio_element_type referenced in an audio element. Ignoring\n"); + ret = 0; + goto fail; + } + codec_config_id = ffio_read_leb(pbc); codec_config = ff_iamf_get_codec_config(c, codec_config_id); @@ -643,14 +680,15 @@ static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) goto fail; } - audio_element->nb_substreams = ffio_read_leb(pbc); + nb_substreams = ffio_read_leb(pbc); audio_element->codec_config_id = codec_config_id; audio_element->audio_element_id = audio_element_id; - audio_element->substreams = av_calloc(audio_element->nb_substreams, sizeof(*audio_element->substreams)); + audio_element->substreams = av_calloc(nb_substreams, sizeof(*audio_element->substreams)); if (!audio_element->substreams) { ret = AVERROR(ENOMEM); goto fail; } + audio_element->nb_substreams = nb_substreams; element = audio_element->element = av_iamf_audio_element_alloc(); if (!element) { @@ -676,7 +714,7 @@ static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) substream->codecpar->codec_id = codec_config->codec_id; substream->codecpar->frame_size = codec_config->nb_samples; substream->codecpar->sample_rate = codec_config->sample_rate; - substream->codecpar->seek_preroll = codec_config->seek_preroll; + substream->codecpar->seek_preroll = -codec_config->audio_roll_distance * codec_config->nb_samples; switch(substream->codecpar->codec_id) { case AV_CODEC_ID_AAC: @@ -695,6 +733,12 @@ static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) } num_parameters = ffio_read_leb(pbc); + if (num_parameters > 2 && audio_element_type == 0) { + av_log(s, AV_LOG_ERROR, "Audio Element parameter count %u is invalid" + " for Channel representations\n", num_parameters); + ret = AVERROR_INVALIDDATA; + goto fail; + } if (num_parameters && audio_element_type != 0) { av_log(s, AV_LOG_ERROR, "Audio Element parameter count %u is invalid" " for Scene representations\n", num_parameters); @@ -708,11 +752,19 @@ static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) type = ffio_read_leb(pbc); if (type == AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN) ret = AVERROR_INVALIDDATA; - else if (type == AV_IAMF_PARAMETER_DEFINITION_DEMIXING) + else if (type == AV_IAMF_PARAMETER_DEFINITION_DEMIXING) { + if (element->demixing_info) { + ret = AVERROR_INVALIDDATA; + goto fail; + } ret = param_parse(s, c, pbc, type, audio_element, &element->demixing_info); - else if (type == AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN) + } else if (type == AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN) { + if (element->recon_gain_info) { + ret = AVERROR_INVALIDDATA; + goto fail; + } ret = param_parse(s, c, pbc, type, audio_element, &element->recon_gain_info); - else { + } else { unsigned param_definition_size = ffio_read_leb(pbc); avio_skip(pbc, param_definition_size); } @@ -729,8 +781,7 @@ static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) if (ret < 0) goto fail; } else { - unsigned audio_element_config_size = ffio_read_leb(pbc); - avio_skip(pbc, audio_element_config_size); + av_assert0(0); } c->audio_elements[c->nb_audio_elements++] = audio_element; @@ -933,6 +984,10 @@ static int mix_presentation_obu(void *s, IAMFContext *c, AVIOContext *pb, int le if (submix_layout->layout_type == 2) { int sound_system; sound_system = (byte >> 2) & 0xF; + if (sound_system >= FF_ARRAY_ELEMS(ff_iamf_sound_system_map)) { + ret = AVERROR_INVALIDDATA; + goto fail; + } av_channel_layout_copy(&submix_layout->sound_system, &ff_iamf_sound_system_map[sound_system].layout); } @@ -1049,6 +1104,7 @@ int ff_iamfdec_read_descriptors(IAMFContext *c, AVIOContext *pb, size = avio_read(pb, header, FFMIN(MAX_IAMF_OBU_HEADER_SIZE, max_size)); if (size < 0) return size; + memset(header + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); len = ff_iamf_parse_obu_header(header, size, &obu_size, &start_pos, &type, NULL, NULL); if (len < 0 || obu_size > max_size) { @@ -1073,8 +1129,6 @@ int ff_iamfdec_read_descriptors(IAMFContext *c, AVIOContext *pb, case IAMF_OBU_IA_MIX_PRESENTATION: ret = mix_presentation_obu(log_ctx, c, pb, obu_size); break; - case IAMF_OBU_IA_TEMPORAL_DELIMITER: - break; default: { int64_t offset = avio_skip(pb, obu_size); if (offset < 0) diff --git a/libavformat/iamf_reader.c b/libavformat/iamf_reader.c index 270cfac389..02e8b694d7 100644 --- a/libavformat/iamf_reader.c +++ b/libavformat/iamf_reader.c @@ -108,6 +108,7 @@ static int parameter_block_obu(AVFormatContext *s, IAMFDemuxContext *c, AVIOContext *pb; uint8_t *buf; unsigned int duration, constant_subblock_duration; + unsigned int total_duration = 0; unsigned int nb_subblocks; unsigned int parameter_id; size_t out_param_size; @@ -146,8 +147,10 @@ static int parameter_block_obu(AVFormatContext *s, IAMFDemuxContext *c, constant_subblock_duration = ffio_read_leb(pb); if (constant_subblock_duration == 0) nb_subblocks = ffio_read_leb(pb); - else + else { nb_subblocks = duration / constant_subblock_duration; + total_duration = duration; + } } else { duration = param->duration; constant_subblock_duration = param->constant_subblock_duration; @@ -171,8 +174,11 @@ static int parameter_block_obu(AVFormatContext *s, IAMFDemuxContext *c, void *subblock = av_iamf_param_definition_get_subblock(out_param, i); unsigned int subblock_duration = constant_subblock_duration; - if (!param_definition->mode && !constant_subblock_duration) + if (!param_definition->mode && !constant_subblock_duration) { subblock_duration = ffio_read_leb(pb); + total_duration += subblock_duration; + } else if (i == nb_subblocks - 1) + subblock_duration = duration - i * constant_subblock_duration; switch (param->type) { case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN: { @@ -234,6 +240,12 @@ static int parameter_block_obu(AVFormatContext *s, IAMFDemuxContext *c, av_log(s, level, "Underread in parameter_block_obu. %d bytes left at the end\n", len); } + if (!param_definition->mode && !constant_subblock_duration && total_duration != duration) { + av_log(s, AV_LOG_ERROR, "Invalid duration in parameter block\n"); + ret = AVERROR_INVALIDDATA; + goto fail; + } + switch (param->type) { case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN: av_free(c->mix); @@ -269,7 +281,7 @@ int ff_iamf_read_packet(AVFormatContext *s, IAMFDemuxContext *c, int read = 0; while (1) { - uint8_t header[MAX_IAMF_OBU_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; + uint8_t header[MAX_IAMF_OBU_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE] = {0}; enum IAMF_OBU_Type type; unsigned obu_size; unsigned skip_samples, discard_padding; @@ -280,12 +292,14 @@ int ff_iamf_read_packet(AVFormatContext *s, IAMFDemuxContext *c, size = avio_read(pb, header, FFMIN(MAX_IAMF_OBU_HEADER_SIZE, max_size)); if (size < 0) return size; + if (size != FFMIN(MAX_IAMF_OBU_HEADER_SIZE, max_size)) + return AVERROR_INVALIDDATA; len = ff_iamf_parse_obu_header(header, size, &obu_size, &start_pos, &type, &skip_samples, &discard_padding); - if (len < 0 || obu_size > max_size) { + if (len < 0 || obu_size > max_size || len > INT_MAX - read) { av_log(s, AV_LOG_ERROR, "Failed to read obu\n"); - return len; + return len < 0 ? len : AVERROR_INVALIDDATA; } avio_seek(pb, -(size - start_pos), SEEK_CUR); diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c index 37ec8e732a..7dfe658bf9 100644 --- a/libavformat/iamf_writer.c +++ b/libavformat/iamf_writer.c @@ -39,11 +39,15 @@ static int update_extradata(IAMFCodecConfig *codec_config) switch(codec_config->codec_id) { case AV_CODEC_ID_OPUS: - if (codec_config->extradata_size < 19) + if (codec_config->extradata_size != 19) return AVERROR_INVALIDDATA; codec_config->extradata_size -= 8; - memmove(codec_config->extradata, codec_config->extradata + 8, codec_config->extradata_size); - AV_WB8(codec_config->extradata + 1, 2); // set channels to stereo + AV_WB8(codec_config->extradata + 0, AV_RL8(codec_config->extradata + 8)); // version + AV_WB8(codec_config->extradata + 1, 2); // set channels to stereo + AV_WB16(codec_config->extradata + 2, AV_RL16(codec_config->extradata + 10)); // Byte swap pre-skip + AV_WB32(codec_config->extradata + 4, AV_RL32(codec_config->extradata + 12)); // Byte swap sample rate + AV_WB16(codec_config->extradata + 8, 0); // set Output Gain to 0 + AV_WB8(codec_config->extradata + 10, AV_RL8(codec_config->extradata + 18)); // Mapping family break; case AV_CODEC_ID_FLAC: { uint8_t buf[13]; @@ -72,6 +76,34 @@ static int update_extradata(IAMFCodecConfig *codec_config) return 0; } +static int populate_audio_roll_distance(IAMFCodecConfig *codec_config) +{ + switch (codec_config->codec_id) { + case AV_CODEC_ID_OPUS: + if (!codec_config->nb_samples) + return AVERROR(EINVAL); + // ceil(3840 / nb_samples) + codec_config->audio_roll_distance = -(1 + ((3840 - 1) / codec_config->nb_samples)); + break; + case AV_CODEC_ID_AAC: + codec_config->audio_roll_distance = -1; + break; + case AV_CODEC_ID_FLAC: + case AV_CODEC_ID_PCM_S16BE: + case AV_CODEC_ID_PCM_S24BE: + case AV_CODEC_ID_PCM_S32BE: + case AV_CODEC_ID_PCM_S16LE: + case AV_CODEC_ID_PCM_S24LE: + case AV_CODEC_ID_PCM_S32LE: + codec_config->audio_roll_distance = 0; + break; + default: + return AVERROR(EINVAL); + } + + return 0; +} + static int fill_codec_config(IAMFContext *iamf, const AVStreamGroup *stg, IAMFCodecConfig *codec_config) { @@ -80,10 +112,18 @@ static int fill_codec_config(IAMFContext *iamf, const AVStreamGroup *stg, int j, ret = 0; codec_config->codec_id = st->codecpar->codec_id; - codec_config->sample_rate = st->codecpar->sample_rate; codec_config->codec_tag = st->codecpar->codec_tag; - codec_config->nb_samples = st->codecpar->frame_size; - codec_config->seek_preroll = st->codecpar->seek_preroll; + switch (codec_config->codec_id) { + case AV_CODEC_ID_OPUS: + codec_config->sample_rate = 48000; + codec_config->nb_samples = av_rescale(st->codecpar->frame_size, 48000, st->codecpar->sample_rate); + break; + default: + codec_config->sample_rate = st->codecpar->sample_rate; + codec_config->nb_samples = st->codecpar->frame_size; + break; + } + populate_audio_roll_distance(codec_config); if (st->codecpar->extradata_size) { codec_config->extradata = av_memdup(st->codecpar->extradata, st->codecpar->extradata_size); if (!codec_config->extradata) @@ -151,9 +191,9 @@ static int add_param_definition(IAMFContext *iamf, AVIAMFParamDefinition *param, } if (codec_config) { if (!param->duration) - param->duration = codec_config->nb_samples; + param->duration = av_rescale(codec_config->nb_samples, param->parameter_rate, codec_config->sample_rate); if (!param->constant_subblock_duration) - param->constant_subblock_duration = codec_config->nb_samples; + param->constant_subblock_duration = av_rescale(codec_config->nb_samples, param->parameter_rate, codec_config->sample_rate); } param_definition = av_mallocz(sizeof(*param_definition)); @@ -177,6 +217,10 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void if (stg->type != AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT) return AVERROR(EINVAL); + if (!stg->nb_streams) { + av_log(log_ctx, AV_LOG_ERROR, "Audio Element id %"PRId64" has no streams\n", stg->id); + return AVERROR(EINVAL); + } iamf_audio_element = stg->params.iamf_audio_element; if (iamf_audio_element->audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE) { @@ -275,6 +319,17 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void } } + for (int i = 0; i < audio_element->nb_substreams; i++) { + for (int j = i + 1; j < audio_element->nb_substreams; j++) + if (audio_element->substreams[i].audio_substream_id == + audio_element->substreams[j].audio_substream_id) { + av_log(log_ctx, AV_LOG_ERROR, "Duplicate id %u in streams %u and %u from stream group %u\n", + audio_element->substreams[i].audio_substream_id, i, j, stg->index); + ret = AVERROR(EINVAL); + goto fail; + } + } + if (iamf_audio_element->demixing_info) { AVIAMFParamDefinition *param = iamf_audio_element->demixing_info; const IAMFParamDefinition *param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id); @@ -330,6 +385,10 @@ int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, vo if (stg->type != AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION) return AVERROR(EINVAL); + if (!stg->nb_streams) { + av_log(log_ctx, AV_LOG_ERROR, "Mix Presentation id %"PRId64" has no streams\n", stg->id); + return AVERROR(EINVAL); + } for (int i = 0; i < iamf->nb_mix_presentations; i++) { if (stg->id == iamf->mix_presentations[i]->mix_presentation_id) { @@ -416,7 +475,7 @@ static int iamf_write_codec_config(const IAMFContext *iamf, avio_wl32(dyn_bc, codec_config->codec_tag); ffio_write_leb(dyn_bc, codec_config->nb_samples); - avio_wb16(dyn_bc, codec_config->seek_preroll); + avio_wb16(dyn_bc, codec_config->audio_roll_distance); switch(codec_config->codec_id) { case AV_CODEC_ID_OPUS: @@ -430,32 +489,32 @@ static int iamf_write_codec_config(const IAMFContext *iamf, avio_write(dyn_bc, codec_config->extradata, codec_config->extradata_size); break; case AV_CODEC_ID_PCM_S16LE: - avio_w8(dyn_bc, 0); + avio_w8(dyn_bc, 1); avio_w8(dyn_bc, 16); avio_wb32(dyn_bc, codec_config->sample_rate); break; case AV_CODEC_ID_PCM_S24LE: - avio_w8(dyn_bc, 0); + avio_w8(dyn_bc, 1); avio_w8(dyn_bc, 24); avio_wb32(dyn_bc, codec_config->sample_rate); break; case AV_CODEC_ID_PCM_S32LE: - avio_w8(dyn_bc, 0); + avio_w8(dyn_bc, 1); avio_w8(dyn_bc, 32); avio_wb32(dyn_bc, codec_config->sample_rate); break; case AV_CODEC_ID_PCM_S16BE: - avio_w8(dyn_bc, 1); + avio_w8(dyn_bc, 0); avio_w8(dyn_bc, 16); avio_wb32(dyn_bc, codec_config->sample_rate); break; case AV_CODEC_ID_PCM_S24BE: - avio_w8(dyn_bc, 1); + avio_w8(dyn_bc, 0); avio_w8(dyn_bc, 24); avio_wb32(dyn_bc, codec_config->sample_rate); break; case AV_CODEC_ID_PCM_S32BE: - avio_w8(dyn_bc, 1); + avio_w8(dyn_bc, 0); avio_w8(dyn_bc, 32); avio_wb32(dyn_bc, codec_config->sample_rate); break; diff --git a/libavformat/iamfdec.c b/libavformat/iamfdec.c index e34d13e74c..ad47c5e5f7 100644 --- a/libavformat/iamfdec.c +++ b/libavformat/iamfdec.c @@ -107,9 +107,9 @@ static int iamf_read_header(AVFormatContext *s) if (ret < 0) return ret; - if (!i && !j && audio_element->layers[0].substream_count == 1) + if (!i && !j && audio_element->nb_layers && audio_element->layers[0].substream_count == 1) st->disposition |= AV_DISPOSITION_DEFAULT; - else + else if (audio_element->nb_layers > 1 || audio_element->layers[0].substream_count > 1) st->disposition |= AV_DISPOSITION_DEPENDENT; st->id = substream->audio_substream_id; avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); @@ -154,6 +154,9 @@ static int iamf_read_header(AVFormatContext *s) } } + if (!s->nb_streams) + return AVERROR_INVALIDDATA; + return 0; } diff --git a/libavformat/icodec.c b/libavformat/icodec.c index 808c7ab795..371deb4bc0 100644 --- a/libavformat/icodec.c +++ b/libavformat/icodec.c @@ -197,7 +197,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) AV_WL32(buf + 32, image->nb_pal); } - if (image->nb_pal > INT_MAX / 4 - 14 - 40) + if (image->nb_pal > INT_MAX / 4 - 14 - 40U) return AVERROR_INVALIDDATA; AV_WL32(buf - 4, 14 + 40 + image->nb_pal * 4); diff --git a/libavformat/iff.c b/libavformat/iff.c index 0cbe125337..be4856aa3d 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -359,6 +359,9 @@ static int read_dst_frame(AVFormatContext *s, AVPacket *pkt) uint64_t chunk_pos, data_pos, data_size; int ret = AVERROR_EOF; + if (s->nb_streams < 1) + return AVERROR_INVALIDDATA; + while (!avio_feof(pb)) { chunk_pos = avio_tell(pb); if (chunk_pos >= iff->body_end) diff --git a/libavformat/ilbc.c b/libavformat/ilbc.c index a24aa3da9d..6c441c21bf 100644 --- a/libavformat/ilbc.c +++ b/libavformat/ilbc.c @@ -61,7 +61,8 @@ static int ilbc_read_header(AVFormatContext *s) AVStream *st; uint8_t header[9]; - avio_read(pb, header, 9); + if (avio_read(pb, header, 9) != 9) + return AVERROR_INVALIDDATA; st = avformat_new_stream(s, NULL); if (!st) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index 4625d720ac..bf56c78266 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -695,12 +695,9 @@ static int imf_read_header(AVFormatContext *s) static IMFVirtualTrackPlaybackCtx *get_next_track_with_minimum_timestamp(AVFormatContext *s) { IMFContext *c = s->priv_data; - IMFVirtualTrackPlaybackCtx *track; + IMFVirtualTrackPlaybackCtx *track = NULL; AVRational minimum_timestamp = av_make_q(INT32_MAX, 1); - if (!c->track_count) - return NULL; - for (uint32_t i = c->track_count; i > 0; i--) { av_log(s, AV_LOG_TRACE, "Compare track %d timestamp " AVRATIONAL_FORMAT " to minimum " AVRATIONAL_FORMAT diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index ff0065aff7..ddefbe85e2 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -25,6 +25,7 @@ #define _DEFAULT_SOURCE #define _BSD_SOURCE #include +#include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/log.h" #include "libavutil/opt.h" @@ -504,6 +505,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) pkt->flags |= AV_PKT_FLAG_KEY; if (s->ts_from_file) { struct stat img_stat; + av_assert0(!s->is_pipe); // The ts_from_file option is not supported by piped input demuxers if (stat(filename, &img_stat)) { res = AVERROR(EIO); goto fail; @@ -561,6 +563,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) } goto fail; } else { + memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE); s->img_count++; s->img_number++; s->pts++; @@ -794,13 +797,14 @@ static int jpeg_probe(const AVProbeData *p) return 0; state = EOI; break; - case DQT: case APP0: - if (AV_RL32(&b[i + 4]) == MKTAG('J','F','I','F')) + if (c == APP0 && AV_RL32(&b[i + 4]) == MKTAG('J','F','I','F')) got_header = 1; + /* fallthrough */ case APP1: - if (AV_RL32(&b[i + 4]) == MKTAG('E','x','i','f')) + if (c == APP1 && AV_RL32(&b[i + 4]) == MKTAG('E','x','i','f')) got_header = 1; + /* fallthrough */ case APP2: case APP3: case APP4: @@ -815,6 +819,7 @@ static int jpeg_probe(const AVProbeData *p) case APP13: case APP14: case APP15: + case DQT: /* fallthrough */ case COM: i += AV_RB16(&b[i + 2]) + 1; break; diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c index 5d1748953a..3701be276f 100644 --- a/libavformat/ipmovie.c +++ b/libavformat/ipmovie.c @@ -614,7 +614,8 @@ static int ipmovie_read_header(AVFormatContext *s) ipmovie->avf = s; - avio_read(pb, signature_buffer, sizeof(signature_buffer)); + if (avio_read(pb, signature_buffer, sizeof(signature_buffer)) != sizeof(signature_buffer)) + return AVERROR_INVALIDDATA; while (memcmp(signature_buffer, signature, sizeof(signature))) { memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1); signature_buffer[sizeof(signature_buffer) - 1] = avio_r8(pb); diff --git a/libavformat/isom.c b/libavformat/isom.c index 9fbccd4437..0e9b7ba0d9 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -292,12 +292,12 @@ int ff_mp4_read_descr_len(AVIOContext *pb) return len; } -int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag) +int ff_mp4_read_descr(void *logctx, AVIOContext *pb, int *tag) { int len; *tag = avio_r8(pb); len = ff_mp4_read_descr_len(pb); - av_log(fc, AV_LOG_TRACE, "MPEG-4 description: tag=0x%02x len=%d\n", *tag, len); + av_log(logctx, AV_LOG_TRACE, "MPEG-4 description: tag=0x%02x len=%d\n", *tag, len); return len; } @@ -326,7 +326,7 @@ static const AVCodecTag mp4_audio_types[] = { { AV_CODEC_ID_NONE, AOT_NULL }, }; -int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb) +int ff_mp4_read_dec_config_descr(void *logctx, AVStream *st, AVIOContext *pb) { enum AVCodecID codec_id; int len, tag; @@ -341,24 +341,25 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id); if (codec_id) st->codecpar->codec_id = codec_id; - av_log(fc, AV_LOG_TRACE, "esds object type id 0x%02x\n", object_type_id); - len = ff_mp4_read_descr(fc, pb, &tag); + av_log(logctx, AV_LOG_TRACE, "esds object type id 0x%02x\n", object_type_id); + len = ff_mp4_read_descr(logctx, pb, &tag); if (tag == MP4DecSpecificDescrTag) { - av_log(fc, AV_LOG_TRACE, "Specific MPEG-4 header len=%d\n", len); + av_log(logctx, AV_LOG_TRACE, "Specific MPEG-4 header len=%d\n", len); /* As per 14496-3:2009 9.D.2.2, No decSpecificInfo is defined for MPEG-1 Audio or MPEG-2 Audio; MPEG-2 AAC excluded. */ if (object_type_id == 0x69 || object_type_id == 0x6b) return 0; if (!len || (uint64_t)len > (1<<30)) return AVERROR_INVALIDDATA; - if ((ret = ff_get_extradata(fc, st->codecpar, pb, len)) < 0) + if ((ret = ff_get_extradata(logctx, st->codecpar, pb, len)) < 0) return ret; if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { MPEG4AudioConfig cfg = {0}; ret = avpriv_mpeg4audio_get_config2(&cfg, st->codecpar->extradata, - st->codecpar->extradata_size, 1, fc); + st->codecpar->extradata_size, 1, logctx); if (ret < 0) return ret; + av_channel_layout_uninit(&st->codecpar->ch_layout); st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; st->codecpar->ch_layout.nb_channels = cfg.channels; if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4 @@ -367,7 +368,7 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext st->codecpar->sample_rate = cfg.ext_sample_rate; else st->codecpar->sample_rate = cfg.sample_rate; - av_log(fc, AV_LOG_TRACE, "mp4a config channels %d obj %d ext obj %d " + av_log(logctx, AV_LOG_TRACE, "mp4a config channels %d obj %d ext obj %d " "sample rate %d ext sample rate %d\n", cfg.channels, cfg.object_type, cfg.ext_object_type, cfg.sample_rate, cfg.ext_sample_rate); diff --git a/libavformat/isom.h b/libavformat/isom.h index 07f09d6eff..b7ccc9994b 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -193,7 +193,7 @@ typedef struct MOVStreamContext { unsigned int sample_size; ///< may contain value calculated from stsd or value from stsz atom unsigned int stsz_sample_size; ///< always contains sample size from stsz atom unsigned int sample_count; - int *sample_sizes; + unsigned int *sample_sizes; int keyframe_absent; unsigned int keyframe_count; int *keyframes; @@ -359,8 +359,8 @@ typedef struct MOVContext { } MOVContext; int ff_mp4_read_descr_len(AVIOContext *pb); -int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag); -int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb); +int ff_mp4_read_descr(void *logctx, AVIOContext *pb, int *tag); +int ff_mp4_read_dec_config_descr(void *logctx, AVStream *st, AVIOContext *pb); void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id); #define MP4ODescrTag 0x01 diff --git a/libavformat/jpegxl_anim_dec.c b/libavformat/jpegxl_anim_dec.c index ac95d3b961..7798f3dabc 100644 --- a/libavformat/jpegxl_anim_dec.c +++ b/libavformat/jpegxl_anim_dec.c @@ -43,7 +43,7 @@ typedef struct JXLAnimDemuxContext { static int jpegxl_anim_probe(const AVProbeData *p) { - uint8_t buffer[4096 + AV_INPUT_BUFFER_PADDING_SIZE]; + uint8_t buffer[4096 + AV_INPUT_BUFFER_PADDING_SIZE] = {0}; int copied = 0, ret; FFJXLMetadata meta = { 0 }; @@ -124,6 +124,8 @@ static int jpegxl_anim_read_header(AVFormatContext *s) } } + memset(head + headsize, 0, AV_INPUT_BUFFER_PADDING_SIZE); + /* offset in bits of the animation header */ ret = ff_jpegxl_parse_codestream_header(head, headsize, &meta, 0); if (ret < 0 || meta.animation_offset <= 0) diff --git a/libavformat/kvag.c b/libavformat/kvag.c index 1d0aee0994..b55aa893ec 100644 --- a/libavformat/kvag.c +++ b/libavformat/kvag.c @@ -38,7 +38,7 @@ typedef struct KVAGHeader { uint32_t magic; uint32_t data_size; - uint32_t sample_rate; + int sample_rate; uint16_t stereo; } KVAGHeader; @@ -70,6 +70,9 @@ static int kvag_read_header(AVFormatContext *s) hdr.sample_rate = AV_RL32(buf + 8); hdr.stereo = AV_RL16(buf + 12); + if (hdr.sample_rate <= 0) + return AVERROR_INVALIDDATA; + par = st->codecpar; par->codec_type = AVMEDIA_TYPE_AUDIO; par->codec_id = AV_CODEC_ID_ADPCM_IMA_SSI; diff --git a/libavformat/libzmq.c b/libavformat/libzmq.c index 04c72ac601..da84efee73 100644 --- a/libavformat/libzmq.c +++ b/libavformat/libzmq.c @@ -94,7 +94,10 @@ static int zmq_proto_open(URLContext *h, const char *uri, int flags) return AVERROR_EXTERNAL; } - av_strstart(uri, "zmq:", &uri); + if (!av_strstart(uri, "zmq:", &uri)) { + av_log(h, AV_LOG_ERROR, "URL %s lacks prefix\n", uri); + return AVERROR(EINVAL); + } /*publish during write*/ if (h->flags & AVIO_FLAG_WRITE) { diff --git a/libavformat/lmlm4.c b/libavformat/lmlm4.c index 209b544ccd..fd5880d9e1 100644 --- a/libavformat/lmlm4.c +++ b/libavformat/lmlm4.c @@ -95,15 +95,15 @@ static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt) if (frame_type > LMLM4_MPEG1L2 || frame_type == LMLM4_INVALID) { av_log(s, AV_LOG_ERROR, "invalid or unsupported frame_type\n"); - return AVERROR(EIO); + return AVERROR_INVALIDDATA; } if (packet_size > LMLM4_MAX_PACKET_SIZE || packet_size<=8) { av_log(s, AV_LOG_ERROR, "packet size %d is invalid\n", packet_size); - return AVERROR(EIO); + return AVERROR_INVALIDDATA; } if ((ret = av_get_packet(pb, pkt, frame_size)) <= 0) - return AVERROR(EIO); + return ret < 0 ? ret : AVERROR(EIO); avio_skip(pb, padding); diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index e37fcfa018..9c4e5b1d80 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -4207,7 +4207,7 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) MatroskaBlock *block = &cluster->block; int res; - av_assert0(matroska->num_levels <= 2); + av_assert0(matroska->num_levels <= 2U); if (matroska->num_levels == 1) { res = ebml_parse(matroska, matroska_segment, NULL); @@ -4580,9 +4580,10 @@ static int64_t webm_dash_manifest_compute_bandwidth(AVFormatContext *s, int64_t // The prebuffer ends in the last Cue. Estimate how much data was // prebuffered. pre_bytes = desc_end.end_offset - desc_end.start_offset; - pre_ns = desc_end.end_time_ns - desc_end.start_time_ns; - if (pre_ns <= 0) + if (desc_end.end_time_ns <= desc_end.start_time_ns || + desc_end.end_time_ns - (uint64_t)desc_end.start_time_ns > INT64_MAX) return -1; + pre_ns = desc_end.end_time_ns - desc_end.start_time_ns; pre_sec = pre_ns / nano_seconds_per_second; prebuffer_bytes += pre_bytes * ((temp_prebuffer_ns / nano_seconds_per_second) / pre_sec); @@ -4595,7 +4596,7 @@ static int64_t webm_dash_manifest_compute_bandwidth(AVFormatContext *s, int64_t int64_t desc_bytes = desc_end.end_offset - desc_beg.start_offset; int64_t desc_ns = desc_end.end_time_ns - desc_beg.start_time_ns; double desc_sec, calc_bits_per_second, percent, mod_bits_per_second; - if (desc_bytes <= 0) + if (desc_bytes <= 0 || desc_bytes > INT64_MAX/8) return -1; desc_sec = desc_ns / nano_seconds_per_second; diff --git a/libavformat/mccdec.c b/libavformat/mccdec.c index 85bf93cd3b..8c0ea09b6b 100644 --- a/libavformat/mccdec.c +++ b/libavformat/mccdec.c @@ -93,7 +93,7 @@ static int mcc_read_header(AVFormatContext *s) { MCCContext *mcc = s->priv_data; AVStream *st = avformat_new_stream(s, NULL); - AVRational rate; + AVRational rate = {0}; int64_t ts, pos; uint8_t out[4096]; char line[4096]; @@ -139,7 +139,7 @@ static int mcc_read_header(AVFormatContext *s) continue; } - if (av_sscanf(line, "%d:%d:%d:%d", &hh, &mm, &ss, &fs) != 4) + if (av_sscanf(line, "%d:%d:%d:%d", &hh, &mm, &ss, &fs) != 4 || rate.den <= 0) continue; ts = av_sat_add64(av_rescale(hh * 3600LL + mm * 60LL + ss, rate.num, rate.den), fs); diff --git a/libavformat/mlvdec.c b/libavformat/mlvdec.c index e3165e3811..f91b95a939 100644 --- a/libavformat/mlvdec.c +++ b/libavformat/mlvdec.c @@ -81,13 +81,15 @@ static int check_file_header(AVIOContext *pb, uint64_t guid) static void read_string(AVFormatContext *avctx, AVIOContext *pb, const char *tag, unsigned size) { char * value = av_malloc(size + 1); + int ret; + if (!value) { avio_skip(pb, size); return; } - avio_read(pb, value, size); - if (!value[0]) { + ret = avio_read(pb, value, size); + if (ret != size || !value[0]) { av_free(value); return; } @@ -434,19 +436,25 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) if (size < 16) return AVERROR_INVALIDDATA; avio_skip(pb, 12); //timestamp, frameNumber - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) + size -= 12; + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (size < 8) + return AVERROR_INVALIDDATA; avio_skip(pb, 8); // cropPosX, cropPosY, panPosX, panPosY + size -= 8; + } space = avio_rl32(pb); + if (size < space + 4LL) + return AVERROR_INVALIDDATA; avio_skip(pb, space); + size -= space; if ((mlv->class[st->id] & (MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA))) { ret = AVERROR_PATCHWELCOME; } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { ret = av_get_packet(pb, pkt, (st->codecpar->width * st->codecpar->height * st->codecpar->bits_per_coded_sample + 7) >> 3); } else { // AVMEDIA_TYPE_AUDIO - if (space > UINT_MAX - 24 || size < (24 + space)) - return AVERROR_INVALIDDATA; - ret = av_get_packet(pb, pkt, size - (24 + space)); + ret = av_get_packet(pb, pkt, size - 4); } if (ret < 0) diff --git a/libavformat/mm.c b/libavformat/mm.c index 23c025d852..e377ed4fbb 100644 --- a/libavformat/mm.c +++ b/libavformat/mm.c @@ -95,7 +95,7 @@ static int read_header(AVFormatContext *s) type = avio_rl16(pb); length = avio_rl32(pb); - if (type != MM_TYPE_HEADER) + if (type != MM_TYPE_HEADER || length < 10) return AVERROR_INVALIDDATA; /* read header */ diff --git a/libavformat/mov.c b/libavformat/mov.c index e7aa8d1833..e0ffb0a405 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -332,7 +332,8 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom) char *str = NULL; const char *key = NULL; uint16_t langcode = 0; - uint32_t data_type = 0, str_size, str_size_alloc; + uint32_t data_type = 0, str_size_alloc; + uint64_t str_size; int (*parse)(MOVContext*, AVIOContext*, unsigned, const char*) = NULL; int raw = 0; int num = 0; @@ -896,6 +897,11 @@ static int mov_read_iacb(MOVContext *c, AVIOContext *pb, MOVAtom atom) st = c->fc->streams[c->fc->nb_streams - 1]; sc = st->priv_data; + if (st->codecpar->extradata) { + av_log(c->fc, AV_LOG_WARNING, "ignoring iacb\n"); + return 0; + } + sc->iamf = av_mallocz(sizeof(*sc->iamf)); if (!sc->iamf) return AVERROR(ENOMEM); @@ -3056,6 +3062,11 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVStreamContext *sc; unsigned int i, entries; + if (c->trak_index < 0) { + av_log(c->fc, AV_LOG_WARNING, "STSC outside TRAK\n"); + return 0; + } + if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams-1]; @@ -3152,6 +3163,11 @@ static int mov_read_stps(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVStreamContext *sc; unsigned i, entries; + if (c->trak_index < 0) { + av_log(c->fc, AV_LOG_WARNING, "STPS outside TRAK\n"); + return 0; + } + if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams-1]; @@ -3189,6 +3205,11 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVStreamContext *sc; unsigned int i, entries; + if (c->trak_index < 0) { + av_log(c->fc, AV_LOG_WARNING, "STSS outside TRAK\n"); + return 0; + } + if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams-1]; @@ -3241,6 +3262,11 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom) unsigned char* buf; int ret; + if (c->trak_index < 0) { + av_log(c->fc, AV_LOG_WARNING, "STSZ outside TRAK\n"); + return 0; + } + if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams-1]; @@ -3305,9 +3331,9 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom) for (i = 0; i < entries; i++) { sc->sample_sizes[i] = get_bits_long(&gb, field_size); - if (sc->sample_sizes[i] < 0) { + if (sc->sample_sizes[i] > INT64_MAX - sc->data_size) { av_free(buf); - av_log(c->fc, AV_LOG_ERROR, "Invalid sample size %d\n", sc->sample_sizes[i]); + av_log(c->fc, AV_LOG_ERROR, "Sample size overflow in STSZ\n"); return AVERROR_INVALIDDATA; } sc->data_size += sc->sample_sizes[i]; @@ -3330,6 +3356,11 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) int64_t current_dts = 0; int64_t corrected_dts = 0; + if (c->trak_index < 0) { + av_log(c->fc, AV_LOG_WARNING, "STTS outside TRAK\n"); + return 0; + } + if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams-1]; @@ -3383,15 +3414,15 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->stts_data[i].duration = 1; corrected_dts += (delta_magnitude < 0 ? (int64_t)delta_magnitude : 1) * sample_count; } else { - corrected_dts += sample_duration * sample_count; + corrected_dts += sample_duration * (uint64_t)sample_count; } - current_dts += sc->stts_data[i].duration * sample_count; + current_dts += sc->stts_data[i].duration * (uint64_t)sample_count; if (current_dts > corrected_dts) { int64_t drift = (current_dts - corrected_dts)/FFMAX(sample_count, 1); uint32_t correction = (sc->stts_data[i].duration > drift) ? drift : sc->stts_data[i].duration - 1; - current_dts -= correction * sample_count; + current_dts -= correction * (uint64_t)sample_count; sc->stts_data[i].duration -= correction; } @@ -3486,6 +3517,11 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVStreamContext *sc; unsigned int i, entries, ctts_count = 0; + if (c->trak_index < 0) { + av_log(c->fc, AV_LOG_WARNING, "CTTS outside TRAK\n"); + return 0; + } + if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams-1]; @@ -3683,6 +3719,10 @@ static int get_edit_list_entry(MOVContext *mov, } *edit_list_duration = av_rescale(*edit_list_duration, msc->time_scale, global_timescale); + + if (*edit_list_duration + (uint64_t)*edit_list_media_time > INT64_MAX) + *edit_list_duration = 0; + return 1; } @@ -4854,31 +4894,30 @@ static int mov_update_iamf_streams(MOVContext *c, const AVStream *st) return 0; } +static int sanity_checks(void *log_obj, MOVStreamContext *sc, int index) +{ + if ((sc->chunk_count && (!sc->stts_count || !sc->stsc_count || + (!sc->sample_size && !sc->sample_count))) || + (!sc->chunk_count && sc->sample_count)) { + av_log(log_obj, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n", + index); + return 1; + } + + if (sc->stsc_count && sc->stsc_data[ sc->stsc_count - 1 ].first > sc->chunk_count) { + av_log(log_obj, AV_LOG_ERROR, "stream %d, contradictionary STSC and STCO\n", + index); + return 2; + } + return 0; +} + static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; MOVStreamContext *sc; int ret; - if (c->found_iinf) { - // * For animated heif, if the iinf box showed up before the moov - // box, we need to clear all the streams read in the former. - for (int i = c->nb_heif_item - 1; i >= 0; i--) { - HEIFItem *item = &c->heif_item[i]; - - av_freep(&item->name); - - if (!item->st) - continue; - - mov_free_stream_context(c->fc, item->st); - ff_remove_stream(c->fc, item->st); - } - av_freep(&c->heif_item); - c->nb_heif_item = 0; - c->found_iinf = c->found_iloc = 0; - } - st = avformat_new_stream(c->fc, NULL); if (!st) return AVERROR(ENOMEM); st->id = -1; @@ -4903,19 +4942,9 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_freep(&sc->stsc_data); } - /* sanity checks */ - if ((sc->chunk_count && (!sc->stts_count || !sc->stsc_count || - (!sc->sample_size && !sc->sample_count))) || - (!sc->chunk_count && sc->sample_count)) { - av_log(c->fc, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n", - st->index); - return 0; - } - if (sc->stsc_count && sc->stsc_data[ sc->stsc_count - 1 ].first > sc->chunk_count) { - av_log(c->fc, AV_LOG_ERROR, "stream %d, contradictionary STSC and STCO\n", - st->index); - return AVERROR_INVALIDDATA; - } + ret = sanity_checks(c->fc, sc, st->index); + if (ret) + return ret > 1 ? AVERROR_INVALIDDATA : 0; fix_timescale(c, sc); @@ -5043,6 +5072,7 @@ static int mov_read_keys(MOVContext *c, AVIOContext *pb, MOVAtom atom) avio_skip(pb, 4); count = avio_rb32(pb); + atom.size -= 8; if (count > UINT_MAX / sizeof(*c->meta_keys) - 1) { av_log(c->fc, AV_LOG_ERROR, "The 'keys' atom with the invalid key count: %"PRIu32"\n", count); @@ -5057,15 +5087,17 @@ static int mov_read_keys(MOVContext *c, AVIOContext *pb, MOVAtom atom) for (i = 1; i <= count; ++i) { uint32_t key_size = avio_rb32(pb); uint32_t type = avio_rl32(pb); - if (key_size < 8) { + if (key_size < 8 || key_size > atom.size) { av_log(c->fc, AV_LOG_ERROR, "The key# %"PRIu32" in meta has invalid size:" "%"PRIu32"\n", i, key_size); return AVERROR_INVALIDDATA; } + atom.size -= key_size; key_size -= 8; if (type != MKTAG('m','d','t','a')) { avio_skip(pb, key_size); + continue; } c->meta_keys[i] = av_mallocz(key_size + 1); if (!c->meta_keys[i]) @@ -6140,8 +6172,10 @@ static int mov_read_smdm(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_WARNING, "Unsupported Mastering Display Metadata box version %d\n", version); return 0; } - if (sc->mastering) - return AVERROR_INVALIDDATA; + if (sc->mastering) { + av_log(c->fc, AV_LOG_WARNING, "Ignoring duplicate Mastering Display Metadata\n"); + return 0; + } avio_skip(pb, 3); /* flags */ @@ -6178,11 +6212,16 @@ static int mov_read_mdcv(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc = c->fc->streams[c->fc->nb_streams - 1]->priv_data; - if (atom.size < 24 || sc->mastering) { + if (atom.size < 24) { av_log(c->fc, AV_LOG_ERROR, "Invalid Mastering Display Color Volume box\n"); return AVERROR_INVALIDDATA; } + if (sc->mastering) { + av_log(c->fc, AV_LOG_WARNING, "Ignoring duplicate Mastering Display Color Volume\n"); + return 0; + } + sc->mastering = av_mastering_display_metadata_alloc(); if (!sc->mastering) return AVERROR(ENOMEM); @@ -8019,7 +8058,7 @@ static int mov_read_SAND(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } -static int rb_size(AVIOContext *pb, uint64_t* value, int size) +static int rb_size(AVIOContext *pb, int64_t *value, int size) { if (size == 0) *value = 0; @@ -8029,9 +8068,11 @@ static int rb_size(AVIOContext *pb, uint64_t* value, int size) *value = avio_rb16(pb); else if (size == 4) *value = avio_rb32(pb); - else if (size == 8) + else if (size == 8) { *value = avio_rb64(pb); - else + if (*value < 0) + return -1; + } else return -1; return size; } @@ -8058,9 +8099,8 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) int64_t base_offset, extent_offset, extent_length; uint8_t value; - if (c->found_moov) { - // * For animated heif, we don't care about the iloc box as all the - // necessary information can be found in the moov box. + if (c->found_iloc) { + av_log(c->fc, AV_LOG_INFO, "Duplicate iloc box found\n"); return 0; } @@ -8112,7 +8152,8 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) } for (int j = 0; j < extent_count; j++) { if (rb_size(pb, &extent_offset, offset_size) < 0 || - rb_size(pb, &extent_length, length_size) < 0) + rb_size(pb, &extent_length, length_size) < 0 || + base_offset > INT64_MAX - extent_offset) return AVERROR_INVALIDDATA; if (offset_type == 1) c->heif_item[i].is_idat_relative = 1; @@ -8139,16 +8180,21 @@ static int mov_read_infe(MOVContext *c, AVIOContext *pb, MOVAtom atom, int idx) version = avio_r8(pb); avio_rb24(pb); // flags. size -= 4; + if (size < 0) + return AVERROR_INVALIDDATA; if (version < 2) { - av_log(c->fc, AV_LOG_ERROR, "infe: version < 2 not supported\n"); - return AVERROR_PATCHWELCOME; + avpriv_report_missing_feature(c->fc, "infe version < 2"); + avio_skip(pb, size); + return 1; } item_id = version > 2 ? avio_rb32(pb) : avio_rb16(pb); avio_rb16(pb); // item_protection_index item_type = avio_rl32(pb); size -= 8; + if (size < 1) + return AVERROR_INVALIDDATA; av_bprint_init(&item_name, 0, AV_BPRINT_SIZE_UNLIMITED); ret = ff_read_string_to_bprint_overwrite(pb, &item_name, size); @@ -8185,17 +8231,12 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, MOVAtom atom) { HEIFItem *heif_item; int entry_count; - int version, ret; + int version, got_stream = 0, ret, i; if (c->found_iinf) { av_log(c->fc, AV_LOG_WARNING, "Duplicate iinf box found\n"); return 0; } - if (c->found_moov) { - // * For animated heif, we don't care about the iinf box as all the - // necessary information can be found in the moov box. - return 0; - } version = avio_r8(pb); avio_rb24(pb); // flags. @@ -8210,18 +8251,35 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, MOVAtom atom) sizeof(*c->heif_item) * (entry_count - c->nb_heif_item)); c->nb_heif_item = FFMAX(c->nb_heif_item, entry_count); - for (int i = 0; i < entry_count; i++) { + for (i = 0; i < entry_count; i++) { MOVAtom infe; + if (avio_feof(pb)) + return AVERROR_INVALIDDATA; infe.size = avio_rb32(pb) - 8; infe.type = avio_rl32(pb); ret = mov_read_infe(c, pb, infe, i); if (ret < 0) - return ret; + goto fail; + if (!ret) + got_stream = 1; } - c->found_iinf = 1; + c->found_iinf = got_stream; return 0; +fail: + for (; i >= 0; i--) { + HEIFItem *item = &c->heif_item[i]; + + av_freep(&item->name); + if (!item->st) + continue; + + mov_free_stream_context(c->fc, item->st); + ff_remove_stream(c->fc, item->st); + item->st = NULL; + } + return ret; } static int mov_read_iref_dimg(MOVContext *c, AVIOContext *pb, int version) @@ -8349,12 +8407,6 @@ static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) { uint32_t width, height; - if (c->found_moov) { - // * For animated heif, we don't care about the ispe box as all the - // necessary information can be found in the moov box. - return 0; - } - avio_r8(pb); /* version */ avio_rb24(pb); /* flags */ width = avio_rb32(pb); @@ -8389,12 +8441,6 @@ static int mov_read_iprp(MOVContext *c, AVIOContext *pb, MOVAtom atom) int version, flags; int ret; - if (c->found_moov) { - // * For animated heif, we don't care about the iprp box as all the - // necessary information can be found in the moov box. - return 0; - } - a.size = avio_rb32(pb); a.type = avio_rl32(pb); @@ -8449,6 +8495,11 @@ static int mov_read_iprp(MOVContext *c, AVIOContext *pb, MOVAtom atom) int item_id = version ? avio_rb32(pb) : avio_rb16(pb); int assoc_count = avio_r8(pb); + if (avio_feof(pb)) { + ret = AVERROR_INVALIDDATA; + goto fail; + } + for (int j = 0; j < assoc_count; j++) { MOVAtoms *ref; int index = avio_r8(pb) & 0x7f; @@ -8478,6 +8529,7 @@ static int mov_read_iprp(MOVContext *c, AVIOContext *pb, MOVAtom atom) ret = 0; fail: + c->cur_item_id = -1; for (int i = 0; i < nb_atoms; i++) av_free(atoms[i].data); av_free(atoms); @@ -8849,7 +8901,7 @@ static void mov_read_chapters(AVFormatContext *s) if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { st->disposition |= AV_DISPOSITION_ATTACHED_PIC | AV_DISPOSITION_TIMED_THUMBNAILS; - if (sti->nb_index_entries) { + if (!st->attached_pic.data && sti->nb_index_entries) { // Retrieve the first frame, if possible AVIndexEntry *sample = &sti->index_entries[0]; if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { @@ -9426,8 +9478,9 @@ static int mov_parse_tiles(AVFormatContext *s) for (int j = 0; j < grid->nb_tiles; j++) { int tile_id = grid->tile_id_list[j]; + int k; - for (int k = 0; k < mov->nb_heif_item; k++) { + for (k = 0; k < mov->nb_heif_item; k++) { HEIFItem *item = &mov->heif_item[k]; AVStream *st = item->st; @@ -9453,6 +9506,14 @@ static int mov_parse_tiles(AVFormatContext *s) break; } + if (k == mov->nb_heif_item) { + av_assert0(loop); + av_log(s, AV_LOG_WARNING, "HEIF item id %d referenced by grid id %d doesn't " + "exist\n", + tile_id, grid->item->item_id); + ff_remove_stream_group(s, stg); + loop = 0; + } if (!loop) break; } @@ -9501,6 +9562,7 @@ static int mov_read_header(AVFormatContext *s) mov->trak_index = -1; mov->thmb_item_id = -1; mov->primary_item_id = -1; + mov->cur_item_id = -1; /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */ if (pb->seekable & AVIO_SEEKABLE_NORMAL) atom.size = avio_size(pb); @@ -9515,14 +9577,15 @@ static int mov_read_header(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "error reading header\n"); return err; } - } while ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mov->found_moov && !mov->found_iloc && !mov->moov_retry++); - if (!mov->found_moov && !mov->found_iloc) { + } while ((pb->seekable & AVIO_SEEKABLE_NORMAL) && + !mov->found_moov && (!mov->found_iloc || !mov->found_iinf) && !mov->moov_retry++); + if (!mov->found_moov && !mov->found_iloc && !mov->found_iinf) { av_log(s, AV_LOG_ERROR, "moov atom not found\n"); return AVERROR_INVALIDDATA; } av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb)); - if (mov->found_iloc) { + if (mov->found_iloc && mov->found_iinf) { for (i = 0; i < mov->nb_heif_item; i++) { HEIFItem *item = &mov->heif_item[i]; MOVStreamContext *sc; @@ -9549,6 +9612,9 @@ static int mov_read_header(AVFormatContext *s) st->codecpar->width = item->width; st->codecpar->height = item->height; + if (sc->sample_count != 1 || sc->chunk_count != 1) + return AVERROR_INVALIDDATA; + sc->sample_sizes[0] = item->extent_length; sc->chunk_offsets[0] = item->extent_offset + offset; @@ -9564,6 +9630,10 @@ static int mov_read_header(AVFormatContext *s) return err; } } + // prevent iloc and iinf boxes from being parsed while reading packets. + // this is needed because an iinf box may have been parsed but ignored + // for having old infe boxes which create no streams. + mov->found_iloc = mov->found_iinf = 1; if (pb->seekable & AVIO_SEEKABLE_NORMAL) { if (mov->nb_chapter_tracks > 0 && !mov->ignore_chapters) @@ -9841,25 +9911,73 @@ static int mov_change_extradata(AVStream *st, AVPacket *pkt) return 0; } -static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size) +static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int src_size) { - int new_size, ret; + /* We can't make assumptions about the structure of the payload, + because it may include multiple cdat and cdt2 samples. */ + const uint32_t cdat = AV_RB32("cdat"); + const uint32_t cdt2 = AV_RB32("cdt2"); + int ret, out_size = 0; - if (size <= 8) + /* a valid payload must have size, 4cc, and at least 1 byte pair: */ + if (src_size < 10) return AVERROR_INVALIDDATA; - new_size = ((size - 8) / 2) * 3; - ret = av_new_packet(pkt, new_size); + + /* avoid an int overflow: */ + if ((src_size - 8) / 2 >= INT_MAX / 3) + return AVERROR_INVALIDDATA; + + ret = av_new_packet(pkt, ((src_size - 8) / 2) * 3); if (ret < 0) return ret; - avio_skip(pb, 8); - for (int j = 0; j < new_size; j += 3) { - pkt->data[j] = 0xFC; - pkt->data[j+1] = avio_r8(pb); - pkt->data[j+2] = avio_r8(pb); + /* parse and re-format the c608 payload in one pass. */ + while (src_size >= 10) { + const uint32_t atom_size = avio_rb32(pb); + const uint32_t atom_type = avio_rb32(pb); + const uint32_t data_size = atom_size - 8; + const uint8_t cc_field = + atom_type == cdat ? 1 : + atom_type == cdt2 ? 2 : + 0; + + /* account for bytes consumed for atom size and type. */ + src_size -= 8; + + /* make sure the data size stays within the buffer boundaries. */ + if (data_size < 2 || data_size > src_size) { + ret = AVERROR_INVALIDDATA; + break; + } + + /* make sure the data size is consistent with N byte pairs. */ + if (data_size % 2 != 0) { + ret = AVERROR_INVALIDDATA; + break; + } + + if (!cc_field) { + /* neither cdat or cdt2 ... skip it */ + avio_skip(pb, data_size); + src_size -= data_size; + continue; + } + + for (uint32_t i = 0; i < data_size; i += 2) { + pkt->data[out_size] = (0x1F << 3) | (1 << 2) | (cc_field - 1); + pkt->data[out_size + 1] = avio_r8(pb); + pkt->data[out_size + 2] = avio_r8(pb); + out_size += 3; + src_size -= 2; + } } - return 0; + if (src_size > 0) + /* skip any remaining unread portion of the input payload */ + avio_skip(pb, src_size); + + av_shrink_packet(pkt, out_size); + return ret; } static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *sample, diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index 287059d65b..3c7274b737 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -462,10 +462,22 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, return 0; if (layout_tag == MOV_CH_LAYOUT_USE_DESCRIPTIONS) { - int nb_channels = ch_layout->nb_channels ? ch_layout->nb_channels : num_descr; - if (num_descr > nb_channels) { - av_log(s, AV_LOG_WARNING, "got %d channel descriptions, capping to the number of channels %d\n", + int nb_channels = ch_layout->nb_channels; + + if (!num_descr || num_descr < nb_channels) { + av_log(s, AV_LOG_ERROR, "got %d channel descriptions when at least %d were needed\n", num_descr, nb_channels); + return AVERROR_INVALIDDATA; + } + + if (num_descr > nb_channels) { + int strict = s->strict_std_compliance >= FF_COMPLIANCE_STRICT; + av_log(s, strict ? AV_LOG_ERROR : AV_LOG_WARNING, + "got %d channel descriptions when number of channels is %d\n", + num_descr, nb_channels); + if (strict) + return AVERROR_INVALIDDATA; + av_log(s, AV_LOG_WARNING, "capping channel descriptions to the number of channels\n"); num_descr = nb_channels; } diff --git a/libavformat/movenc.c b/libavformat/movenc.c index b97c479cc4..6241a66f90 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -1222,6 +1222,8 @@ static int mov_write_chnl_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra if (ret || !config) { config = 0; speaker_pos = av_malloc(layout->nb_channels); + if (!speaker_pos) + return AVERROR(ENOMEM); ret = ff_mov_get_channel_positions_from_layout(layout, speaker_pos, layout->nb_channels); if (ret) { @@ -1339,7 +1341,8 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex avio_wb16(pb, 16); avio_wb16(pb, track->audio_vbr ? -2 : 0); /* compression ID */ } else { /* reserved for mp4/3gp */ - avio_wb16(pb, track->par->ch_layout.nb_channels); + avio_wb16(pb, track->tag == MKTAG('i', 'a', 'm', 'f') ? + 0 : track->par->ch_layout.nb_channels); if (track->par->codec_id == AV_CODEC_ID_FLAC || track->par->codec_id == AV_CODEC_ID_ALAC) { avio_wb16(pb, track->par->bits_per_raw_sample); @@ -1350,7 +1353,9 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex } avio_wb16(pb, 0); /* packet size (= 0) */ - if (track->par->codec_id == AV_CODEC_ID_OPUS) + if (track->tag == MKTAG('i','a','m','f')) + avio_wb16(pb, 0); /* samplerate must be 0 for IAMF */ + else if (track->par->codec_id == AV_CODEC_ID_OPUS) avio_wb16(pb, 48000); else if (track->par->codec_id == AV_CODEC_ID_TRUEHD) avio_wb32(pb, track->par->sample_rate); @@ -4871,7 +4876,8 @@ static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov, AVFormat param_write_int(pb, "AudioTag", ff_codec_get_tag(ff_codec_wav_tags, track->par->codec_id)); param_write_int(pb, "Channels", track->par->ch_layout.nb_channels); - param_write_int(pb, "SamplingRate", track->par->sample_rate); + param_write_int(pb, "SamplingRate", track->tag == MKTAG('i','a','m','f') ? + 0 : track->par->sample_rate); param_write_int(pb, "BitsPerSample", 16); param_write_int(pb, "PacketSize", track->par->block_align ? track->par->block_align : 4); @@ -6195,6 +6201,12 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) return ret; + if (pkt->pts != AV_NOPTS_VALUE && + (uint64_t)pkt->dts - pkt->pts != (int32_t)((uint64_t)pkt->dts - pkt->pts)) { + av_log(s, AV_LOG_WARNING, "pts/dts pair unsupported\n"); + return AVERROR_PATCHWELCOME; + } + if (mov->flags & FF_MOV_FLAG_FRAGMENT || mov->mode == MODE_AVIF) { int ret; if (mov->moov_written || mov->flags & FF_MOV_FLAG_EMPTY_MOOV) { @@ -7143,7 +7155,9 @@ static int mov_create_dvd_sub_decoder_specific_info(MOVTrack *track, static int mov_init_iamf_track(AVFormatContext *s) { MOVMuxContext *mov = s->priv_data; - MOVTrack *track = &mov->tracks[0]; // IAMF if present is always the first track + MOVTrack *track; + IAMFContext *iamf; + int first_iamf_idx = INT_MAX, last_iamf_idx = 0; int nb_audio_elements = 0, nb_mix_presentations = 0; int ret; @@ -7165,24 +7179,24 @@ static int mov_init_iamf_track(AVFormatContext *s) return AVERROR(EINVAL); } - track->iamf = av_mallocz(sizeof(*track->iamf)); - if (!track->iamf) + iamf = av_mallocz(sizeof(*iamf)); + if (!iamf) return AVERROR(ENOMEM); + for (int i = 0; i < s->nb_stream_groups; i++) { const AVStreamGroup *stg = s->stream_groups[i]; switch(stg->type) { case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: for (int j = 0; j < stg->nb_streams; j++) { - track->first_iamf_idx = FFMIN(stg->streams[j]->index, track->first_iamf_idx); - track->last_iamf_idx = FFMAX(stg->streams[j]->index, track->last_iamf_idx); - stg->streams[j]->priv_data = track; + first_iamf_idx = FFMIN(stg->streams[j]->index, first_iamf_idx); + last_iamf_idx = FFMAX(stg->streams[j]->index, last_iamf_idx); } - ret = ff_iamf_add_audio_element(track->iamf, stg, s); + ret = ff_iamf_add_audio_element(iamf, stg, s); break; case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: - ret = ff_iamf_add_mix_presentation(track->iamf, stg, s); + ret = ff_iamf_add_mix_presentation(iamf, stg, s); break; default: av_assert0(0); @@ -7191,8 +7205,20 @@ static int mov_init_iamf_track(AVFormatContext *s) return ret; } + track = &mov->tracks[first_iamf_idx]; + track->iamf = iamf; + track->first_iamf_idx = first_iamf_idx; + track->last_iamf_idx = last_iamf_idx; track->tag = MKTAG('i','a','m','f'); + for (int i = 0; i < s->nb_stream_groups; i++) { + AVStreamGroup *stg = s->stream_groups[i]; + if (stg->type != AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT) + continue; + for (int j = 0; j < stg->nb_streams; j++) + stg->streams[j]->priv_data = track; + } + ret = avio_open_dyn_buf(&track->iamf_buf); if (ret < 0) return ret; @@ -7203,6 +7229,7 @@ static int mov_init_iamf_track(AVFormatContext *s) static int mov_init(AVFormatContext *s) { MOVMuxContext *mov = s->priv_data; + int has_iamf = 0; int i, ret; mov->fc = s; @@ -7353,6 +7380,7 @@ static int mov_init(AVFormatContext *s) } st->priv_data = st; } + has_iamf = 1; if (!mov->nb_tracks) // We support one track for the entire IAMF structure mov->nb_tracks++; @@ -7449,8 +7477,11 @@ static int mov_init(AVFormatContext *s) for (int j = 0, i = 0; j < s->nb_streams; j++) { AVStream *st = s->streams[j]; - if (st != st->priv_data) + if (st != st->priv_data) { + if (has_iamf) + i += has_iamf--; continue; + } st->priv_data = &mov->tracks[i++]; } diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index ec6cf567bc..0029ba63aa 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -32,6 +32,7 @@ #include "replaygain.h" #include "libavcodec/codec_id.h" +#include "libavcodec/mpegaudio.h" #include "libavcodec/mpegaudiodecheader.h" #define XING_FLAG_FRAMES 0x01 @@ -136,9 +137,10 @@ static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration int fill_index = (mp3->usetoc || fast_seek) && duration > 0; if (!filesize && - !(filesize = avio_size(s->pb))) { + (filesize = avio_size(s->pb)) <= 0) { av_log(s, AV_LOG_WARNING, "Cannot determine file size, skipping TOC table.\n"); fill_index = 0; + filesize = 0; } for (i = 0; i < XING_TOC_COUNT; i++) { @@ -400,27 +402,22 @@ static int mp3_read_header(AVFormatContext *s) if (ret < 0) return ret; + ret = ffio_ensure_seekback(s->pb, 64 * 1024 + MPA_MAX_CODED_FRAME_SIZE + 4); + if (ret < 0) + return ret; + off = avio_tell(s->pb); for (i = 0; i < 64 * 1024; i++) { uint32_t header, header2; int frame_size; - if (!(i&1023)) - ffio_ensure_seekback(s->pb, i + 1024 + 4); frame_size = check(s->pb, off + i, &header); if (frame_size > 0) { - ffio_ensure_seekback(s->pb, i + 1024 + frame_size + 4); ret = check(s->pb, off + i + frame_size, &header2); - if (ret >= 0 && - (header & MP3_MASK) == (header2 & MP3_MASK)) - { + if (ret >= 0 && (header & MP3_MASK) == (header2 & MP3_MASK)) break; - } else if (ret == CHECK_SEEK_FAILED) { - av_log(s, AV_LOG_ERROR, "Invalid frame size (%d): Could not seek to %"PRId64".\n", frame_size, off + i + frame_size); - return AVERROR(EINVAL); - } } else if (frame_size == CHECK_SEEK_FAILED) { - av_log(s, AV_LOG_ERROR, "Failed to read frame size: Could not seek to %"PRId64".\n", (int64_t) (i + 1024 + frame_size + 4)); - return AVERROR(EINVAL); + av_log(s, AV_LOG_ERROR, "Failed to find two consecutive MPEG audio frames.\n"); + return AVERROR_INVALIDDATA; } } if (i == 64 * 1024) { @@ -588,7 +585,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, if (best_pos < 0) return best_pos; - if (mp3->is_cbr && ie == &ie1 && mp3->frames) { + if (mp3->is_cbr && ie == &ie1 && mp3->frames && mp3->header_filesize > 0) { int frame_duration = av_rescale(st->duration, 1, mp3->frames); ie1.timestamp = frame_duration * av_rescale(best_pos - si->data_offset, mp3->frames, mp3->header_filesize); } diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index 904a79d9a7..b30bb44aef 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -75,6 +75,9 @@ static int mpegps_probe(const AVProbeData *p) int pes = endpes <= i && check_pes(p->buf + i, p->buf + p->buf_size); int pack = check_pack_header(p->buf + i); + if (len > INT_MAX - i) + break; + if (code == SYSTEM_HEADER_START_CODE) sys++; else if (code == PACK_START_CODE && pack) @@ -562,7 +565,9 @@ redo: static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 }; unsigned char buf[8]; - avio_read(s->pb, buf, 8); + ret = avio_read(s->pb, buf, 8); + if (ret != 8) + return AVERROR_INVALIDDATA; avio_seek(s->pb, -8, SEEK_CUR); if (!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1)) codec_id = AV_CODEC_ID_CAVS; diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index de7a3c8b45..4e07fe5828 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1674,6 +1674,8 @@ static int mp4_read_iods(AVFormatContext *s, const uint8_t *buf, unsigned size, MP4DescrParseContext d; int ret; + d.predefined_SLConfigDescriptor_seen = 0; + ret = init_MP4DescrParseContext(&d, s, buf, size, descr, max_descr_count); if (ret < 0) return ret; @@ -2605,7 +2607,8 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len FFSWAP(struct Program, ts->prg[nb_prg], ts->prg[prg_idx]); if (prg_idx >= nb_prg) nb_prg++; - } + } else + nb_prg = 0; } } ts->nb_prg = nb_prg; diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c index 31640f7590..0e1ae07443 100644 --- a/libavformat/mvdec.c +++ b/libavformat/mvdec.c @@ -255,7 +255,8 @@ static int read_table(AVFormatContext *avctx, AVStream *st, if (avio_feof(pb)) return AVERROR_EOF; - avio_read(pb, name, 16); + if (avio_read(pb, name, 16) != 16) + return AVERROR_INVALIDDATA; name[sizeof(name) - 1] = 0; size = avio_rb32(pb); if (size < 0) { diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index c9af462855..9c771b5856 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -250,7 +250,7 @@ typedef struct MXFFFV1SubDescriptor { typedef struct MXFIndexTableSegment { MXFMetadataSet meta; - int edit_unit_byte_count; + unsigned edit_unit_byte_count; int index_sid; int body_sid; AVRational index_edit_rate; @@ -672,7 +672,8 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv if (size < 32 || size - 32 < orig_size || (int)orig_size != orig_size) return AVERROR_INVALIDDATA; avio_read(pb, ivec, 16); - avio_read(pb, tmpbuf, 16); + if (avio_read(pb, tmpbuf, 16) != 16) + return AVERROR_INVALIDDATA; if (mxf->aesc) av_aes_crypt(mxf->aesc, tmpbuf, tmpbuf, 1, ivec, 1); if (memcmp(tmpbuf, checkv, 16)) @@ -790,6 +791,9 @@ static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size partition->index_sid = avio_rb32(pb); partition->body_offset = avio_rb64(pb); partition->body_sid = avio_rb32(pb); + if (partition->body_offset < 0) + return AVERROR_INVALIDDATA; + if (avio_read(pb, op, sizeof(UID)) != sizeof(UID)) { av_log(mxf->fc, AV_LOG_ERROR, "Failed reading UID\n"); return AVERROR_INVALIDDATA; @@ -1263,6 +1267,9 @@ static int mxf_read_index_table_segment(void *arg, AVIOContext *pb, int tag, int case 0x3F0B: segment->index_edit_rate.num = avio_rb32(pb); segment->index_edit_rate.den = avio_rb32(pb); + if (segment->index_edit_rate.num <= 0 || + segment->index_edit_rate.den <= 0) + return AVERROR_INVALIDDATA; av_log(NULL, AV_LOG_TRACE, "IndexEditRate %d/%d\n", segment->index_edit_rate.num, segment->index_edit_rate.den); break; @@ -1525,7 +1532,8 @@ static int mxf_read_indirect_value(void *arg, AVIOContext *pb, int size) if (size <= 17) return 0; - avio_read(pb, key, 17); + if (avio_read(pb, key, 17) != 17) + return AVERROR_INVALIDDATA; /* TODO: handle other types of of indirect values */ if (memcmp(key, mxf_indirect_value_utf16le, 17) == 0) { return mxf_read_utf16le_string(pb, size - 17, &tagged_value->value); @@ -1891,9 +1899,13 @@ static int mxf_edit_unit_absolute_offset(MXFContext *mxf, MXFIndexTable *index_t if (edit_unit < s->index_start_position + s->index_duration) { int64_t index = edit_unit - s->index_start_position; - if (s->edit_unit_byte_count) + if (s->edit_unit_byte_count) { + if (index > INT64_MAX / s->edit_unit_byte_count || + s->edit_unit_byte_count * index > INT64_MAX - offset_temp) + return AVERROR_INVALIDDATA; + offset_temp += s->edit_unit_byte_count * index; - else { + } else { if (s->nb_index_entries == 2 * s->index_duration + 1) index *= 2; /* Avid index */ @@ -1912,6 +1924,11 @@ static int mxf_edit_unit_absolute_offset(MXFContext *mxf, MXFIndexTable *index_t return mxf_absolute_bodysid_offset(mxf, index_table->body_sid, offset_temp, offset_out, partition_out); } else { /* EditUnitByteCount == 0 for VBR indexes, which is fine since they use explicit StreamOffsets */ + if (s->edit_unit_byte_count && (s->index_duration > INT64_MAX / s->edit_unit_byte_count || + s->edit_unit_byte_count * s->index_duration > INT64_MAX - offset_temp) + ) + return AVERROR_INVALIDDATA; + offset_temp += s->edit_unit_byte_count * s->index_duration; } } @@ -2379,6 +2396,9 @@ static int mxf_parse_physical_source_package(MXFContext *mxf, MXFTrack *source_t physical_track->edit_rate, source_track->edit_rate); + if (av_sat_add64(start_position, mxf_tc->start_frame) != start_position + (uint64_t)mxf_tc->start_frame) + return AVERROR_INVALIDDATA; + if (av_timecode_init(&tc, mxf_tc->rate, flags, start_position + mxf_tc->start_frame, mxf->fc) == 0) { mxf_add_timecode_metadata(&st->metadata, "timecode", &tc); return 0; @@ -3020,6 +3040,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) if (container_ul->desc) av_dict_set(&st->metadata, "data_type", container_ul->desc, 0); if (mxf->eia608_extract && + container_ul->desc && !strcmp(container_ul->desc, "vbi_vanc_smpte_436M")) { st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_EIA_608; @@ -3808,9 +3829,8 @@ static int mxf_get_next_track_edit_unit(MXFContext *mxf, MXFTrack *track, int64_ a = -1; b = track->original_duration; - - while (b - a > 1) { - m = (a + b) >> 1; + while (b - 1 > a) { + m = (a + (uint64_t)b) >> 1; if (mxf_edit_unit_absolute_offset(mxf, t, m, track->edit_rate, NULL, &offset, NULL, 0) < 0) return -1; if (offset < current_offset) @@ -3863,7 +3883,7 @@ static int64_t mxf_set_current_edit_unit(MXFContext *mxf, AVStream *st, int64_t int64_t new_edit_unit; MXFIndexTable *t = mxf_find_index_table(mxf, track->index_sid); - if (!t || track->wrapping == UnknownWrapped) + if (!t || track->wrapping == UnknownWrapped || edit_unit > INT64_MAX - track->edit_units_per_packet) return -1; if (mxf_edit_unit_absolute_offset(mxf, t, edit_unit + track->edit_units_per_packet, track->edit_rate, NULL, &next_ofs, NULL, 0) < 0 && diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index adc31c1cf4..d4fa2bc5bb 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2605,9 +2605,6 @@ static int mxf_parse_ffv1_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); v = get_ffv1_unsigned_symbol(&c, state); av_assert0(v >= 2); - if (v > 4) { - return 0; - } if (v > 4) { av_log(s, AV_LOG_ERROR, "unsupported ffv1 version %d\n", v); return 0; diff --git a/libavformat/nistspheredec.c b/libavformat/nistspheredec.c index 1e6c567e01..e624036149 100644 --- a/libavformat/nistspheredec.c +++ b/libavformat/nistspheredec.c @@ -35,7 +35,7 @@ static int nist_probe(const AVProbeData *p) static int nist_read_header(AVFormatContext *s) { - char buffer[256], coding[32] = "pcm", format[32] = "01"; + char buffer[256]= {0}, coding[32] = "pcm", format[32] = "01"; int bps = 0, be = 0; int32_t header_size = -1; AVStream *st; diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c index 112c21fc8e..bb91db8378 100644 --- a/libavformat/nsvdec.c +++ b/libavformat/nsvdec.c @@ -616,7 +616,7 @@ null_chunk_retry: pkt = &nsv->ahead[NSV_ST_AUDIO]; /* read raw audio specific header on the first audio chunk... */ /* on ALL audio chunks ?? seems so! */ - if (asize && st[NSV_ST_AUDIO]->codecpar->codec_tag == MKTAG('P', 'C', 'M', ' ')/* && fill_header*/) { + if (asize >= 4 && st[NSV_ST_AUDIO]->codecpar->codec_tag == MKTAG('P', 'C', 'M', ' ')/* && fill_header*/) { uint8_t bps; uint8_t channels; uint16_t samplerate; diff --git a/libavformat/pcm.c b/libavformat/pcm.c index 051e86dd46..a774dbc372 100644 --- a/libavformat/pcm.c +++ b/libavformat/pcm.c @@ -41,7 +41,7 @@ int ff_pcm_default_packet_size(AVCodecParameters *par) /* Don't trust the codecpar bitrate if we can calculate it ourselves */ if (bits_per_sample > 0 && par->sample_rate > 0 && par->ch_layout.nb_channels > 0) if ((int64_t)par->sample_rate * par->ch_layout.nb_channels < INT64_MAX / bits_per_sample) - bitrate = bits_per_sample * par->sample_rate * par->ch_layout.nb_channels; + bitrate = bits_per_sample * (int64_t)par->sample_rate * par->ch_layout.nb_channels; if (bitrate > 0) { nb_samples = av_clip64(bitrate / 8 / PCM_DEMUX_TARGET_FPS / par->block_align, 1, max_samples); diff --git a/libavformat/qcp.c b/libavformat/qcp.c index fdf18618d2..13a479a11e 100644 --- a/libavformat/qcp.c +++ b/libavformat/qcp.c @@ -105,7 +105,8 @@ static int qcp_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; - avio_read(pb, buf, 16); + if (avio_read(pb, buf, 16) != 16) + return AVERROR_INVALIDDATA; if (is_qcelp_13k_guid(buf)) { st->codecpar->codec_id = AV_CODEC_ID_QCELP; } else if (!memcmp(buf, guid_evrc, 16)) { diff --git a/libavformat/rdt.c b/libavformat/rdt.c index 4721f01ace..9a6b9b53d8 100644 --- a/libavformat/rdt.c +++ b/libavformat/rdt.c @@ -205,6 +205,8 @@ ff_rdt_parse_header(const uint8_t *buf, int len, return -1; /* not followed by a data packet */ pkt_len = AV_RB16(buf+3); + if (pkt_len > len) + return AVERROR_INVALIDDATA; buf += pkt_len; len -= pkt_len; consumed += pkt_len; diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index 2e75aba2a6..fc49a1d29f 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -187,7 +187,8 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, st->codecpar->ch_layout.nb_channels = avio_rb16(pb); if (version == 5) { ast->deint_id = avio_rl32(pb); - avio_read(pb, buf, 4); + if (avio_read(pb, buf, 4) != 4) + return AVERROR_INVALIDDATA; buf[4] = 0; } else { AV_WL32(buf, 0); @@ -267,9 +268,9 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, case DEINT_ID_INT4: if (ast->coded_framesize > ast->audio_framesize || sub_packet_h <= 1 || - ast->coded_framesize * (uint64_t)sub_packet_h > (2 + (sub_packet_h & 1)) * ast->audio_framesize) + ast->coded_framesize * (uint64_t)sub_packet_h > (2LL + (sub_packet_h & 1)) * ast->audio_framesize) return AVERROR_INVALIDDATA; - if (ast->coded_framesize * (uint64_t)sub_packet_h != 2*ast->audio_framesize) { + if (ast->coded_framesize * (uint64_t)sub_packet_h != 2LL*ast->audio_framesize) { avpriv_request_sample(s, "mismatching interleaver parameters"); return AVERROR_INVALIDDATA; } diff --git a/libavformat/rpl.c b/libavformat/rpl.c index 09d0b68f74..31ddd2b3fe 100644 --- a/libavformat/rpl.c +++ b/libavformat/rpl.c @@ -102,7 +102,7 @@ static AVRational read_fps(const char* line, int* error) line++; for (; *line>='0' && *line<='9'; line++) { // Truncate any numerator too large to fit into an int64_t - if (num > (INT64_MAX - 9) / 10 || den > INT64_MAX / 10) + if (num > (INT64_MAX - 9) / 10ULL || den > INT64_MAX / 10ULL) break; num = 10 * num + (*line - '0'); den *= 10; @@ -203,6 +203,8 @@ static int rpl_read_header(AVFormatContext *s) ast->codecpar->codec_tag = audio_format; ast->codecpar->sample_rate = read_line_and_int(pb, &error); // audio bitrate channels = read_line_and_int(pb, &error); // number of audio channels + if (channels <= 0) + return AVERROR_INVALIDDATA; error |= read_line(pb, line, sizeof(line)); ast->codecpar->bits_per_coded_sample = read_int(line, &endptr, &error); // audio bits per sample av_strlcpy(audio_type, endptr, RPL_LINE_LENGTH); diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index a602bf6a96..905469c14f 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -441,7 +441,6 @@ static int amf_tag_skip(GetByteContext *gb) { AMFDataType type; unsigned nb = -1; - int parse_key = 1; if (bytestream2_get_bytes_left(gb) < 1) return -1; @@ -466,13 +465,12 @@ static int amf_tag_skip(GetByteContext *gb) bytestream2_skip(gb, 10); return 0; case AMF_DATA_TYPE_ARRAY: - parse_key = 0; case AMF_DATA_TYPE_MIXEDARRAY: nb = bytestream2_get_be32(gb); case AMF_DATA_TYPE_OBJECT: - while (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY) { + while (type != AMF_DATA_TYPE_ARRAY || nb-- > 0) { int t; - if (parse_key) { + if (type != AMF_DATA_TYPE_ARRAY) { int size = bytestream2_get_be16(gb); if (!size) { bytestream2_get_byte(gb); diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 4b01b67d28..09882a4995 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -2667,7 +2667,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags, AVDictionary **o } if (!strcmp(proto, "rtmpt") || !strcmp(proto, "rtmpts")) { if (!strcmp(proto, "rtmpts")) - av_dict_set(opts, "ffrtmphttp_tls", "1", 1); + av_dict_set(opts, "ffrtmphttp_tls", "1", AV_DICT_MATCH_CASE); /* open the http tunneling connection */ ff_url_join(buf, sizeof(buf), "ffrtmphttp", NULL, hostname, port, NULL); @@ -2917,10 +2917,6 @@ reconnect: return 0; fail: - av_freep(&rt->playpath); - av_freep(&rt->tcurl); - av_freep(&rt->flashver); - av_dict_free(opts); rtmp_close(s); return ret; } diff --git a/libavformat/rtpenc_rfc4175.c b/libavformat/rtpenc_rfc4175.c index 257d072cd3..2120274f01 100644 --- a/libavformat/rtpenc_rfc4175.c +++ b/libavformat/rtpenc_rfc4175.c @@ -116,7 +116,7 @@ void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size, int l_field; int l_line; int l_off; - int copy_offset; + int64_t copy_offset; length = (headers[0] << 8) | headers[1]; l_field = (headers[2] & 0x80) >> 7; @@ -127,7 +127,7 @@ void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size, if (interlaced) l_line = 2 * l_line + l_field; - copy_offset = (l_line * width + l_off) * pgroup / xinc; + copy_offset = (l_line * (int64_t)width + l_off) * pgroup / xinc; if (copy_offset + length > size) break; memcpy (dest, buf + copy_offset, length); diff --git a/libavformat/rtpenc_vc2hq.c b/libavformat/rtpenc_vc2hq.c index 085204fa64..cf548191d2 100644 --- a/libavformat/rtpenc_vc2hq.c +++ b/libavformat/rtpenc_vc2hq.c @@ -45,7 +45,7 @@ static void send_packet(AVFormatContext *ctx, uint8_t parse_code, int info_hdr_s ff_rtp_send_data(ctx, rtp_ctx->buf, RTP_VC2HQ_PL_HEADER_SIZE + info_hdr_size + size, rtp_m); } -static void send_picture(AVFormatContext *ctx, const uint8_t *buf, int size, int interlaced) +static int send_picture(AVFormatContext *ctx, const uint8_t *buf, int size, int interlaced) { RTPMuxContext *rtp_ctx = ctx->priv_data; GetBitContext gc; @@ -54,6 +54,9 @@ static void send_picture(AVFormatContext *ctx, const uint8_t *buf, int size, int uint16_t frag_len; char *info_hdr = &rtp_ctx->buf[4]; + if (size < DIRAC_PIC_NR_SIZE) + return AVERROR(EINVAL); + pic_nr = AV_RB32(&buf[0]); buf += DIRAC_PIC_NR_SIZE; size -= DIRAC_PIC_NR_SIZE; @@ -97,6 +100,7 @@ static void send_picture(AVFormatContext *ctx, const uint8_t *buf, int size, int send_packet(ctx, DIRAC_RTP_PCODE_HQ_PIC_FRAGMENT, 16, buf, frag_len, interlaced, second_field, size > 0 ? 0 : 1); buf += frag_len; } + return 0; } void ff_rtp_send_vc2hq(AVFormatContext *ctx, const uint8_t *frame_buf, int frame_size, int interlaced) @@ -110,16 +114,21 @@ void ff_rtp_send_vc2hq(AVFormatContext *ctx, const uint8_t *frame_buf, int frame parse_code = unit[4]; unit_size = AV_RB32(&unit[5]); + if (unit_size > end - unit) + break; + switch (parse_code) { /* sequence header */ /* end of sequence */ case DIRAC_PCODE_SEQ_HEADER: case DIRAC_PCODE_END_SEQ: - send_packet(ctx, parse_code, 0, unit + DIRAC_DATA_UNIT_HEADER_SIZE, unit_size - DIRAC_DATA_UNIT_HEADER_SIZE, 0, 0, 0); + if (unit_size >= DIRAC_DATA_UNIT_HEADER_SIZE) + send_packet(ctx, parse_code, 0, unit + DIRAC_DATA_UNIT_HEADER_SIZE, unit_size - DIRAC_DATA_UNIT_HEADER_SIZE, 0, 0, 0); break; /* HQ picture */ case DIRAC_PCODE_PICTURE_HQ: - send_picture(ctx, unit + DIRAC_DATA_UNIT_HEADER_SIZE, unit_size - DIRAC_DATA_UNIT_HEADER_SIZE, interlaced); + if (unit_size >= DIRAC_DATA_UNIT_HEADER_SIZE) + send_picture(ctx, unit + DIRAC_DATA_UNIT_HEADER_SIZE, unit_size - DIRAC_DATA_UNIT_HEADER_SIZE, interlaced); break; /* parse codes without specification */ case DIRAC_PCODE_AUX: diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 9a20481f21..caf7fcd2d2 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -1428,7 +1428,7 @@ retry: cur_auth_type = rt->auth_state.auth_type; if ((ret = rtsp_send_cmd_with_content_async(s, method, url, header, send_content, - send_content_length))) + send_content_length)) < 0) return ret; if ((ret = ff_rtsp_read_reply(s, reply, content_ptr, 0, method) ) < 0) @@ -1461,6 +1461,8 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, char cmd[MAX_URL_SIZE]; const char *trans_pref; + memset(&reply1, 0, sizeof(reply1)); + if (rt->transport == RTSP_TRANSPORT_RDT) trans_pref = "x-pn-tng"; else if (rt->transport == RTSP_TRANSPORT_RAW) @@ -1575,7 +1577,11 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, else if (lower_transport == RTSP_LOWER_TRANSPORT_UDP_MULTICAST) { snprintf(transport, sizeof(transport) - 1, "%s/UDP;multicast", trans_pref); + } else { + err = AVERROR(EINVAL); + goto fail; // transport would be uninitialized } + if (s->oformat) { av_strlcat(transport, ";mode=record", sizeof(transport)); } else if (rt->server_type == RTSP_SERVER_REAL || diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c index 7480697f83..710eb408b4 100644 --- a/libavformat/sapdec.c +++ b/libavformat/sapdec.c @@ -197,6 +197,9 @@ static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt) struct pollfd p = {fd, POLLIN, 0}; uint8_t recvbuf[RTP_MAX_PACKET_LENGTH]; + if (fd < 0) + return fd; + if (sap->eof) return AVERROR_EOF; diff --git a/libavformat/sauce.c b/libavformat/sauce.c index 5ac9ca9d14..a9ee9697a3 100644 --- a/libavformat/sauce.c +++ b/libavformat/sauce.c @@ -34,7 +34,12 @@ int ff_sauce_read(AVFormatContext *avctx, uint64_t *fsize, int *got_width, int g AVIOContext *pb = avctx->pb; char buf[36]; int datatype, filetype, t1, t2, nb_comments; - uint64_t start_pos = avio_size(pb) - 128; + int64_t start_pos = avio_size(pb); + + if (start_pos < 128) + return AVERROR_INVALIDDATA; + + start_pos -= 128; avio_seek(pb, start_pos, SEEK_SET); if (avio_read(pb, buf, 7) != 7) diff --git a/libavformat/sdp.c b/libavformat/sdp.c index 6888936290..69e285afe6 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -202,6 +202,8 @@ static int extradata2psets(AVFormatContext *s, const AVCodecParameters *par, continue; } if (p != (psets + strlen(pset_string))) { + if (p - psets >= MAX_PSET_SIZE) + goto fail_in_loop; *p = ','; p++; } @@ -212,6 +214,7 @@ static int extradata2psets(AVFormatContext *s, const AVCodecParameters *par, if (!av_base64_encode(p, MAX_PSET_SIZE - (p - psets), r, r1 - r)) { av_log(s, AV_LOG_ERROR, "Cannot Base64-encode %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"!\n", MAX_PSET_SIZE - (p - psets), r1 - r); +fail_in_loop: av_free(psets); av_free(tmpbuf); diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c index f86845f35e..44ce1f6787 100644 --- a/libavformat/segafilm.c +++ b/libavformat/segafilm.c @@ -234,6 +234,7 @@ static int film_read_header(AVFormatContext *s) else if (film->audio_type != AV_CODEC_ID_NONE) audio_frame_counter += (film->sample_table[i].sample_size / (film->audio_channels * film->audio_bits / 8)); + film->sample_table[i].keyframe = 1; } else { film->sample_table[i].stream = film->video_stream_index; film->sample_table[i].pts = AV_RB32(&scratch[8]) & 0x7FFFFFFF; diff --git a/libavformat/siff.c b/libavformat/siff.c index 5aad03d870..b33746d51d 100644 --- a/libavformat/siff.c +++ b/libavformat/siff.c @@ -199,7 +199,10 @@ static int siff_read_packet(AVFormatContext *s, AVPacket *pkt) if (c->cur_frame >= c->frames) return AVERROR_EOF; if (c->curstrm == -1) { - c->pktsize = avio_rl32(s->pb) - 4; + unsigned pktsize = avio_rl32(s->pb); + if (pktsize < 4) + return AVERROR_INVALIDDATA; + c->pktsize = pktsize - 4; c->flags = avio_rl16(s->pb); if (c->flags & VB_HAS_AUDIO && !c->has_audio) return AVERROR_INVALIDDATA; diff --git a/libavformat/subfile.c b/libavformat/subfile.c index 633a9e3c62..be48ef72ef 100644 --- a/libavformat/subfile.c +++ b/libavformat/subfile.c @@ -18,6 +18,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/opt.h" #include "url.h" @@ -123,9 +124,9 @@ static int64_t subfile_seek(URLContext *h, int64_t pos, int whence) return end; } - if (whence == AVSEEK_SIZE) - return end - c->start; switch (whence) { + case AVSEEK_SIZE: + return end - c->start; case SEEK_SET: new_pos = c->start + pos; break; @@ -135,6 +136,8 @@ static int64_t subfile_seek(URLContext *h, int64_t pos, int whence) case SEEK_END: new_pos = end + pos; break; + default: + av_assert0(0); } if (new_pos < c->start) return AVERROR(EINVAL); diff --git a/libavformat/tls_schannel.c b/libavformat/tls_schannel.c index d4959f75fa..bbeb8a81f2 100644 --- a/libavformat/tls_schannel.c +++ b/libavformat/tls_schannel.c @@ -388,7 +388,7 @@ static int tls_read(URLContext *h, uint8_t *buf, int len) SECURITY_STATUS sspi_ret = SEC_E_OK; SecBuffer inbuf[4]; SecBufferDesc inbuf_desc; - int size, ret; + int size, ret = 0; int min_enc_buf_size = len + SCHANNEL_FREE_BUFFER_SIZE; /* If we have some left-over data from previous network activity, diff --git a/libavformat/tty.c b/libavformat/tty.c index 95b7200527..c3956ccf34 100644 --- a/libavformat/tty.c +++ b/libavformat/tty.c @@ -123,13 +123,16 @@ static int read_header(AVFormatContext *avctx) s->chars_per_frame = FFMAX(av_q2d(st->time_base)*s->chars_per_frame, 1); if (avctx->pb->seekable & AVIO_SEEKABLE_NORMAL) { - s->fsize = avio_size(avctx->pb); - st->duration = (s->fsize + s->chars_per_frame - 1) / s->chars_per_frame; + int64_t fsize = avio_size(avctx->pb); + if (fsize > 0) { + s->fsize = fsize; + st->duration = (s->fsize + s->chars_per_frame - 1) / s->chars_per_frame; - if (ff_sauce_read(avctx, &s->fsize, 0, 0) < 0) - efi_read(avctx, s->fsize - 51); + if (ff_sauce_read(avctx, &s->fsize, 0, 0) < 0) + efi_read(avctx, s->fsize - 51); - avio_seek(avctx->pb, 0, SEEK_SET); + avio_seek(avctx->pb, 0, SEEK_SET); + } } fail: diff --git a/libavformat/ty.c b/libavformat/ty.c index 71707f750f..4a1c820c08 100644 --- a/libavformat/ty.c +++ b/libavformat/ty.c @@ -48,7 +48,7 @@ static const uint8_t ty_AC3AudioPacket[] = { 0x00, 0x00, 0x01, 0xbd }; #define CHUNK_PEEK_COUNT 3 /* number of chunks to probe */ typedef struct TyRecHdr { - int64_t rec_size; + int32_t rec_size; uint8_t ex[2]; uint8_t rec_type; uint8_t subrec_type; diff --git a/libavformat/usmdec.c b/libavformat/usmdec.c index 0c4e8d41be..5a57c59ea0 100644 --- a/libavformat/usmdec.c +++ b/libavformat/usmdec.c @@ -119,7 +119,7 @@ static int parse_utf(AVFormatContext *s, AVIOContext *pb, for (int i = 0; i < nb_items; i++) { GetByteContext *xgb; uint8_t key[256]; - int64_t value; + int64_t value = -1; int n = 0; type = bytestream2_get_byte(&gb); diff --git a/libavformat/vividas.c b/libavformat/vividas.c index ee4048415e..84d9c39f8a 100644 --- a/libavformat/vividas.c +++ b/libavformat/vividas.c @@ -566,7 +566,8 @@ static int viv_read_header(AVFormatContext *s) v = avio_r8(pb); avio_seek(pb, v, SEEK_CUR); - avio_read(pb, keybuffer, 187); + if (avio_read(pb, keybuffer, 187) != 187) + return AVERROR_INVALIDDATA; key = decode_key(keybuffer); viv->sb_key = key; diff --git a/libavformat/vqf.c b/libavformat/vqf.c index 409c014a92..3fdb7d1781 100644 --- a/libavformat/vqf.c +++ b/libavformat/vqf.c @@ -50,22 +50,28 @@ static int vqf_probe(const AVProbeData *probe_packet) return AVPROBE_SCORE_EXTENSION; } -static void add_metadata(AVFormatContext *s, uint32_t tag, +static int add_metadata(AVFormatContext *s, uint32_t tag, unsigned int tag_len, unsigned int remaining) { int len = FFMIN(tag_len, remaining); char *buf, key[5] = {0}; + int ret; if (len == UINT_MAX) - return; + return AVERROR_INVALIDDATA; buf = av_malloc(len+1); if (!buf) - return; - avio_read(s->pb, buf, len); + return AVERROR(ENOMEM); + + ret = avio_read(s->pb, buf, len); + if (ret < 0) + return ret; + if (len != ret) + return AVERROR_INVALIDDATA; buf[len] = 0; AV_WL32(key, tag); - av_dict_set(&s->metadata, key, buf, AV_DICT_DONT_STRDUP_VAL); + return av_dict_set(&s->metadata, key, buf, AV_DICT_DONT_STRDUP_VAL); } static const AVMetadataConv vqf_metadata_conv[] = { @@ -163,7 +169,9 @@ static int vqf_read_header(AVFormatContext *s) avio_skip(s->pb, FFMIN(len, header_size)); break; default: - add_metadata(s, chunk_tag, len, header_size); + ret = add_metadata(s, chunk_tag, len, header_size); + if (ret < 0) + return ret; break; } diff --git a/libavformat/vvc.c b/libavformat/vvc.c index 14a4c0a2f3..d5b3237aeb 100644 --- a/libavformat/vvc.c +++ b/libavformat/vvc.c @@ -21,8 +21,10 @@ */ #include "libavcodec/get_bits.h" +#include "libavcodec/put_bits.h" #include "libavcodec/golomb.h" #include "libavcodec/vvc.h" +#include "libavutil/avassert.h" #include "libavutil/intreadwrite.h" #include "avc.h" #include "avio.h" @@ -184,7 +186,7 @@ static void vvcc_parse_ptl(GetBitContext *gb, unsigned int profileTierPresentFlag, unsigned int max_sub_layers_minus1) { - VVCCProfileTierLevel general_ptl; + VVCCProfileTierLevel general_ptl = { 0 }; int j; if (profileTierPresentFlag) { @@ -266,6 +268,8 @@ static int vvcc_parse_vps(GetBitContext *gb, if (vps_max_layers_minus1 > 0 && vps_max_sublayers_minus1 > 0) vps_default_ptl_dpb_hrd_max_tid_flag = get_bits1(gb); + else + vps_default_ptl_dpb_hrd_max_tid_flag = 0; if (vps_max_layers_minus1 > 0) vps_all_independent_layers_flag = get_bits1(gb); else @@ -274,10 +278,11 @@ static int vvcc_parse_vps(GetBitContext *gb, for (int i = 0; i <= vps_max_layers_minus1; i++) { skip_bits(gb, 6); //vps_layer_id[i] if (i > 0 && !vps_all_independent_layers_flag) { - if (get_bits1(gb)) { // vps_independent_layer_flag[i] + if (!get_bits1(gb)) { // vps_independent_layer_flag[i] unsigned int vps_max_tid_ref_present_flag = get_bits1(gb); for (int j = 0; j < i; j++) { - if (vps_max_tid_ref_present_flag && get_bits1(gb)) // vps_direct_ref_layer_flag[i][j] + unsigned int vps_direct_ref_layer_flag = get_bits1(gb); + if (vps_max_tid_ref_present_flag && vps_direct_ref_layer_flag) skip_bits(gb, 3); // vps_max_tid_il_ref_pics_plus1 } } @@ -325,6 +330,7 @@ static int vvcc_parse_vps(GetBitContext *gb, for (int i = 0; i <= vps_num_ptls_minus1; i++) vvcc_parse_ptl(gb, vvcc, vps_pt_present_flag[i], vps_ptl_max_tid[i]); + vvcc->ptl_present_flag = 1; /* nothing useful for vvcc past this point */ return 0; @@ -355,8 +361,10 @@ static int vvcc_parse_sps(GetBitContext *gb, vvcc->chroma_format_idc = get_bits(gb, 2); sps_log2_ctu_size_minus5 = get_bits(gb, 2); - if (get_bits1(gb)) // sps_ptl_dpb_hrd_params_present_flag + if (get_bits1(gb)) { // sps_ptl_dpb_hrd_params_present_flag + vvcc->ptl_present_flag = 1; vvcc_parse_ptl(gb, vvcc, 1, sps_max_sublayers_minus1); + } skip_bits1(gb); // sps_gdr_enabled_flag if (get_bits(gb, 1)) // sps_ref_pic_resampling_enabled_flag @@ -384,6 +392,7 @@ static int vvcc_parse_sps(GetBitContext *gb, const int tmp_height_val = AV_CEIL_RSHIFT(sps_pic_height_max_in_luma_samples, ctb_log2_size_y); const int wlen = av_ceil_log2(tmp_width_val); const int hlen = av_ceil_log2(tmp_height_val); + unsigned int sps_subpic_id_len; if (sps_num_subpics_minus1 > 0) { // sps_num_subpics_minus1 sps_independent_subpics_flag = get_bits1(gb); sps_subpic_same_size_flag = get_bits1(gb); @@ -403,11 +412,11 @@ static int vvcc_parse_sps(GetBitContext *gb, skip_bits(gb, 2); // sps_subpic_treated_as_pic_flag && sps_loop_filter_across_subpic_enabled_flag } } - get_ue_golomb_long(gb); // sps_subpic_id_len_minus1 + sps_subpic_id_len = get_ue_golomb_long(gb) + 1; if (get_bits1(gb)) { // sps_subpic_id_mapping_explicitly_signalled_flag if (get_bits1(gb)) // sps_subpic_id_mapping_present_flag for (int i = 0; i <= sps_num_subpics_minus1; i++) { - skip_bits1(gb); // sps_subpic_id[i] + skip_bits_long(gb, sps_subpic_id_len); // sps_subpic_id[i] } } } @@ -578,10 +587,8 @@ static void vvcc_init(VVCDecoderConfigurationRecord *vvcc) { memset(vvcc, 0, sizeof(VVCDecoderConfigurationRecord)); vvcc->lengthSizeMinusOne = 3; // 4 bytes - - vvcc->ptl.num_bytes_constraint_info = 1; - - vvcc->ptl_present_flag = 1; + vvcc->ptl.ptl_frame_only_constraint_flag = + vvcc->ptl.ptl_multilayer_enabled_flag = 1; } static void vvcc_close(VVCDecoderConfigurationRecord *vvcc) @@ -602,7 +609,6 @@ static int vvcc_write(AVIOContext *pb, VVCDecoderConfigurationRecord *vvcc) { uint8_t i; uint16_t j, vps_count = 0, sps_count = 0, pps_count = 0; - unsigned char *buf = NULL; /* * It's unclear how to properly compute these fields, so * let's always set them to values meaning 'unspecified'. @@ -734,6 +740,10 @@ static int vvcc_write(AVIOContext *pb, VVCDecoderConfigurationRecord *vvcc) avio_w8(pb, vvcc->lengthSizeMinusOne << 1 | vvcc->ptl_present_flag | 0xf8); if (vvcc->ptl_present_flag) { + uint8_t buf[64]; + PutBitContext pbc; + + init_put_bits(&pbc, buf, sizeof(buf)); /* * unsigned int(9) ols_idx; * unsigned int(3) num_sublayers; @@ -765,15 +775,14 @@ static int vvcc_write(AVIOContext *pb, VVCDecoderConfigurationRecord *vvcc) * unsigned int (1) ptl_frame_only_constraint_flag * unsigned int (1) ptl_multilayer_enabled_flag * unsigned int (8*num_bytes_constraint_info -2) general_constraint_info */ - buf = - (unsigned char *) malloc(sizeof(unsigned char) * - vvcc->ptl.num_bytes_constraint_info); - *buf = vvcc->ptl.ptl_frame_only_constraint_flag << vvcc->ptl. - num_bytes_constraint_info * 8 - 1 | vvcc->ptl. - ptl_multilayer_enabled_flag << vvcc->ptl.num_bytes_constraint_info * - 8 - 2 | *vvcc->ptl.general_constraint_info >> 2; - avio_write(pb, buf, vvcc->ptl.num_bytes_constraint_info); - free(buf); + put_bits(&pbc, 1, vvcc->ptl.ptl_frame_only_constraint_flag); + put_bits(&pbc, 1, vvcc->ptl.ptl_multilayer_enabled_flag); + av_assert0(vvcc->ptl.num_bytes_constraint_info); + if (vvcc->ptl.num_bytes_constraint_info > 1) + ff_copy_bits(&pbc, vvcc->ptl.general_constraint_info, (vvcc->ptl.num_bytes_constraint_info - 1) * 8); + put_bits(&pbc, 6, vvcc->ptl.general_constraint_info[vvcc->ptl.num_bytes_constraint_info - 1] & 0x3f); + flush_put_bits(&pbc); + avio_write(pb, buf, put_bytes_count(&pbc, 1)); if (vvcc->num_sublayers > 1) { uint8_t ptl_sublayer_level_present_flags = 0; diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 0fed1ee639..135da04840 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -873,8 +873,7 @@ static int w64_read_header(AVFormatContext *s) uint8_t guid[16]; int ret; - avio_read(pb, guid, 16); - if (memcmp(guid, ff_w64_guid_riff, 16)) + if (avio_read(pb, guid, 16) != 16 || memcmp(guid, ff_w64_guid_riff, 16)) return AVERROR_INVALIDDATA; /* riff + wave + fmt + sizes */ @@ -912,10 +911,10 @@ static int w64_read_header(AVFormatContext *s) if (st->codecpar->block_align && st->codecpar->ch_layout.nb_channels < FF_SANE_NB_CHANNELS && st->codecpar->bits_per_coded_sample < 128) { - int block_align = st->codecpar->block_align; + int64_t block_align = st->codecpar->block_align; block_align = FFMAX(block_align, - ((st->codecpar->bits_per_coded_sample + 7) / 8) * + ((st->codecpar->bits_per_coded_sample + 7LL) / 8) * st->codecpar->ch_layout.nb_channels); if (block_align > st->codecpar->block_align) { av_log(s, AV_LOG_WARNING, "invalid block_align: %d, broken file.\n", diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c index 1c5b93e0ab..ce0d046aa9 100644 --- a/libavformat/webpenc.c +++ b/libavformat/webpenc.c @@ -190,7 +190,7 @@ static int webp_write_trailer(AVFormatContext *s) if (!ret) { filesize = avio_tell(s->pb); - if (avio_seek(s->pb, 4, SEEK_SET) == 4) { + if (filesize >= 8 && avio_seek(s->pb, 4, SEEK_SET) == 4) { avio_wl32(s->pb, filesize - 8); // Note: without the following, avio only writes 8 bytes to the file. avio_seek(s->pb, filesize, SEEK_SET); diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c index f41b0f2c68..2294d626cd 100644 --- a/libavformat/wtvdec.c +++ b/libavformat/wtvdec.c @@ -184,7 +184,7 @@ static AVIOContext * wtvfile_open_sector(unsigned first_sector, uint64_t length, int nb_sectors1 = read_ints(s->pb, sectors1, WTV_SECTOR_SIZE / 4); int i; - wf->sectors = av_malloc_array(nb_sectors1, 1 << WTV_SECTOR_BITS); + wf->sectors = av_calloc(nb_sectors1, 1 << WTV_SECTOR_BITS); if (!wf->sectors) { av_free(wf); return NULL; @@ -832,7 +832,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p int stream_index = ff_find_stream_index(s, sid); if (stream_index >= 0) { AVStream *st = s->streams[stream_index]; - uint8_t buf[258]; + uint8_t buf[258] = {0}; const uint8_t *pbuf = buf; int buf_size; @@ -845,7 +845,8 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p } buf_size = FFMIN(len - consumed, sizeof(buf)); - avio_read(pb, buf, buf_size); + if (avio_read(pb, buf, buf_size) != buf_size) + return AVERROR_INVALIDDATA; consumed += buf_size; ff_parse_mpeg2_descriptor(s, st, 0, &pbuf, buf + buf_size, NULL, 0, 0, NULL); } diff --git a/libavformat/xmv.c b/libavformat/xmv.c index 6a44d82016..cd58d96c54 100644 --- a/libavformat/xmv.c +++ b/libavformat/xmv.c @@ -220,6 +220,8 @@ static int xmv_read_header(AVFormatContext *s) /* Initialize the packet context */ xmv->next_packet_offset = avio_tell(pb); + if (this_packet_size < xmv->next_packet_offset) + return AVERROR_INVALIDDATA; xmv->next_packet_size = this_packet_size - xmv->next_packet_offset; xmv->stream_count = xmv->audio_track_count + 1; diff --git a/libavutil/aarch64/cpu.c b/libavutil/aarch64/cpu.c index 7a05391343..5ddc7ca888 100644 --- a/libavutil/aarch64/cpu.c +++ b/libavutil/aarch64/cpu.c @@ -64,6 +64,44 @@ static int detect_flags(void) return flags; } +#elif defined(__OpenBSD__) +#include +#include +#include +#include + +static int detect_flags(void) +{ + int flags = 0; + +#ifdef CPU_ID_AA64ISAR0 + int mib[2]; + uint64_t isar0; + uint64_t isar1; + size_t len; + + mib[0] = CTL_MACHDEP; + mib[1] = CPU_ID_AA64ISAR0; + len = sizeof(isar0); + if (sysctl(mib, 2, &isar0, &len, NULL, 0) != -1) { + if (ID_AA64ISAR0_DP(isar0) >= ID_AA64ISAR0_DP_IMPL) + flags |= AV_CPU_FLAG_DOTPROD; + } + + mib[0] = CTL_MACHDEP; + mib[1] = CPU_ID_AA64ISAR1; + len = sizeof(isar1); + if (sysctl(mib, 2, &isar1, &len, NULL, 0) != -1) { +#ifdef ID_AA64ISAR1_I8MM_IMPL + if (ID_AA64ISAR1_I8MM(isar1) >= ID_AA64ISAR1_I8MM_IMPL) + flags |= AV_CPU_FLAG_I8MM; +#endif + } +#endif + + return flags; +} + #elif defined(_WIN32) #include diff --git a/libavutil/avstring.c b/libavutil/avstring.c index 2071dd36a5..875eb691db 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -452,10 +452,12 @@ int av_match_list(const char *name, const char *list, char separator) if (k && (!p[k] || p[k] == separator)) return 1; q = strchr(q, separator); - q += !!q; + if(q) + q++; } p = strchr(p, separator); - p += !!p; + if (p) + p++; } return 0; diff --git a/libavutil/base64.c b/libavutil/base64.c index 3e66f4fcbe..69e11e6f5e 100644 --- a/libavutil/base64.c +++ b/libavutil/base64.c @@ -127,10 +127,12 @@ validity_check: } out3: - *dst++ = v >> 10; + if (end - dst) + *dst++ = v >> 10; v <<= 2; out2: - *dst++ = v >> 4; + if (end - dst) + *dst++ = v >> 4; out1: out0: return bits & 1 ? AVERROR_INVALIDDATA : out ? dst - out : 0; diff --git a/libavutil/buffer.c b/libavutil/buffer.c index e4562a79b1..a8101d83f0 100644 --- a/libavutil/buffer.c +++ b/libavutil/buffer.c @@ -264,7 +264,10 @@ AVBufferPool *av_buffer_pool_init2(size_t size, void *opaque, if (!pool) return NULL; - ff_mutex_init(&pool->mutex, NULL); + if (ff_mutex_init(&pool->mutex, NULL)) { + av_free(pool); + return NULL; + } pool->size = size; pool->opaque = opaque; @@ -283,7 +286,10 @@ AVBufferPool *av_buffer_pool_init(size_t size, AVBufferRef* (*alloc)(size_t size if (!pool) return NULL; - ff_mutex_init(&pool->mutex, NULL); + if (ff_mutex_init(&pool->mutex, NULL)) { + av_free(pool); + return NULL; + } pool->size = size; pool->alloc = alloc ? alloc : av_buffer_alloc; diff --git a/libavutil/frame.c b/libavutil/frame.c index d7a32cdc92..67fbf89f19 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -711,16 +711,14 @@ AVBufferRef *av_frame_get_plane_buffer(const AVFrame *frame, int plane) return NULL; } -static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd, - int *nb_sd, - enum AVFrameSideDataType type, - AVBufferRef *buf) +static AVFrameSideData *add_side_data_from_buf_ext(AVFrameSideData ***sd, + int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef *buf, uint8_t *data, + size_t size) { AVFrameSideData *ret, **tmp; - if (!buf) - return NULL; - // *nb_sd + 1 needs to fit into an int and a size_t. if ((unsigned)*nb_sd >= FFMIN(INT_MAX, SIZE_MAX)) return NULL; @@ -735,8 +733,8 @@ static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd, return NULL; ret->buf = buf; - ret->data = ret->buf->data; - ret->size = buf->size; + ret->data = data; + ret->size = size; ret->type = type; (*sd)[(*nb_sd)++] = ret; @@ -744,6 +742,17 @@ static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd, return ret; } +static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd, + int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef *buf) +{ + if (!buf) + return NULL; + + return add_side_data_from_buf_ext(sd, nb_sd, type, buf, buf->data, buf->size); +} + AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf) @@ -799,7 +808,8 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) remove_side_data(sd, nb_sd, src->type); - sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf); + sd_dst = add_side_data_from_buf_ext(sd, nb_sd, src->type, buf, + src->data, src->size); if (!sd_dst) { av_buffer_unref(&buf); return AVERROR(ENOMEM); @@ -1008,7 +1018,7 @@ int av_frame_apply_cropping(AVFrame *frame, int flags) if (log2_crop_align < min_log2_align) return AVERROR_BUG; - if (min_log2_align < 5) { + if (min_log2_align < 5 && log2_crop_align != INT_MAX) { frame->crop_left &= ~((1 << (5 + log2_crop_align - min_log2_align)) - 1); calc_cropping_offsets(offsets, frame, desc); } diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c index e30c8fc238..553428e67f 100644 --- a/libavutil/hwcontext_d3d11va.c +++ b/libavutil/hwcontext_d3d11va.c @@ -189,6 +189,7 @@ static AVBufferRef *wrap_texture_buf(AVHWFramesContext *ctx, ID3D11Texture2D *te sizeof(*frames_hwctx->texture_infos)); if (!frames_hwctx->texture_infos) { ID3D11Texture2D_Release(tex); + av_free(desc); return NULL; } s->nb_surfaces = s->nb_surfaces_used + 1; @@ -201,7 +202,7 @@ static AVBufferRef *wrap_texture_buf(AVHWFramesContext *ctx, ID3D11Texture2D *te desc->texture = tex; desc->index = index; - buf = av_buffer_create((uint8_t *)desc, sizeof(desc), free_texture, tex, 0); + buf = av_buffer_create((uint8_t *)desc, sizeof(*desc), free_texture, tex, 0); if (!buf) { ID3D11Texture2D_Release(tex); av_free(desc); diff --git a/libavutil/hwcontext_dxva2.c b/libavutil/hwcontext_dxva2.c index 77f34919a8..377bf6eb7f 100644 --- a/libavutil/hwcontext_dxva2.c +++ b/libavutil/hwcontext_dxva2.c @@ -146,7 +146,7 @@ static AVBufferRef *dxva2_pool_alloc(void *opaque, size_t size) if (s->nb_surfaces_used < hwctx->nb_surfaces) { s->nb_surfaces_used++; return av_buffer_create((uint8_t*)s->surfaces_internal[s->nb_surfaces_used - 1], - sizeof(*hwctx->surfaces), dxva2_pool_release_dummy, 0, 0); + sizeof(**hwctx->surfaces), dxva2_pool_release_dummy, 0, 0); } return NULL; diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index c7c7878644..ce71d0ff2d 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -36,6 +36,7 @@ #include "hwcontext_d3d11va.h" #endif #if CONFIG_DXVA2 +#include #include "hwcontext_dxva2.h" #endif @@ -687,7 +688,7 @@ static int qsv_d3d11_update_config(void *ctx, mfxHDL handle, mfxConfig cfg) IDXGIDevice *pDXGIDevice = NULL; HRESULT hr; ID3D11Device *device = handle; - mfxVariant impl_value; + mfxVariant impl_value = {0}; hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void**)&pDXGIDevice); if (SUCCEEDED(hr)) { @@ -753,13 +754,15 @@ static int qsv_d3d9_update_config(void *ctx, mfxHDL handle, mfxConfig cfg) #if CONFIG_DXVA2 mfxStatus sts; IDirect3DDeviceManager9* devmgr = handle; - IDirect3DDevice9Ex *device = NULL; + IDirect3DDevice9 *device = NULL; + IDirect3DDevice9Ex *device_ex = NULL; HANDLE device_handle = 0; IDirect3D9Ex *d3d9ex = NULL; + IDirect3D9 *d3d9 = NULL; LUID luid; D3DDEVICE_CREATION_PARAMETERS params; HRESULT hr; - mfxVariant impl_value; + mfxVariant impl_value = {0}; hr = IDirect3DDeviceManager9_OpenDeviceHandle(devmgr, &device_handle); if (FAILED(hr)) { @@ -773,18 +776,31 @@ static int qsv_d3d9_update_config(void *ctx, mfxHDL handle, mfxConfig cfg) IDirect3DDeviceManager9_CloseDeviceHandle(devmgr, device_handle); goto fail; } - - hr = IDirect3DDevice9Ex_GetCreationParameters(device, ¶ms); + hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **)&device_ex); + IDirect3DDevice9_Release(device); if (FAILED(hr)) { - av_log(ctx, AV_LOG_ERROR, "Error IDirect3DDevice9_GetCreationParameters %d\n", hr); - IDirect3DDevice9Ex_Release(device); + av_log(ctx, AV_LOG_ERROR, "Error IDirect3DDevice9_QueryInterface %d\n", hr); goto unlock; } - hr = IDirect3DDevice9Ex_GetDirect3D(device, &d3d9ex); + hr = IDirect3DDevice9Ex_GetCreationParameters(device_ex, ¶ms); if (FAILED(hr)) { - av_log(ctx, AV_LOG_ERROR, "Error IDirect3DDevice9Ex_GetAdapterLUID %d\n", hr); - IDirect3DDevice9Ex_Release(device); + av_log(ctx, AV_LOG_ERROR, "Error IDirect3DDevice9_GetCreationParameters %d\n", hr); + IDirect3DDevice9Ex_Release(device_ex); + goto unlock; + } + + hr = IDirect3DDevice9Ex_GetDirect3D(device_ex, &d3d9); + if (FAILED(hr)) { + av_log(ctx, AV_LOG_ERROR, "Error IDirect3DDevice9Ex_GetDirect3D %d\n", hr); + IDirect3DDevice9Ex_Release(device_ex); + goto unlock; + } + hr = IDirect3D9_QueryInterface(d3d9, &IID_IDirect3D9Ex, (void **)&d3d9ex); + IDirect3D9_Release(d3d9); + if (FAILED(hr)) { + av_log(ctx, AV_LOG_ERROR, "Error IDirect3D9_QueryInterface3D %d\n", hr); + IDirect3DDevice9Ex_Release(device_ex); goto unlock; } @@ -808,7 +824,7 @@ static int qsv_d3d9_update_config(void *ctx, mfxHDL handle, mfxConfig cfg) release: IDirect3D9Ex_Release(d3d9ex); - IDirect3DDevice9Ex_Release(device); + IDirect3DDevice9Ex_Release(device_ex); unlock: IDirect3DDeviceManager9_UnlockDevice(devmgr, device_handle, FALSE); @@ -828,7 +844,7 @@ static int qsv_va_update_config(void *ctx, mfxHDL handle, mfxConfig cfg) VADisplayAttribute attr = { .type = VADisplayPCIID, }; - mfxVariant impl_value; + mfxVariant impl_value = {0}; vas = vaGetDisplayAttributes(dpy, &attr, 1); if (vas == VA_STATUS_SUCCESS && attr.flags != VA_DISPLAY_ATTRIB_NOT_SUPPORTED) { @@ -869,7 +885,7 @@ static int qsv_new_mfx_loader(void *ctx, mfxStatus sts; mfxLoader loader = NULL; mfxConfig cfg; - mfxVariant impl_value; + mfxVariant impl_value = {0}; *ploader = NULL; loader = MFXLoad(); @@ -1368,8 +1384,9 @@ static int qsv_frames_derive_from(AVHWFramesContext *dst_ctx, case AV_HWDEVICE_TYPE_D3D11VA: { D3D11_TEXTURE2D_DESC texDesc; + AVD3D11VAFramesContext *dst_hwctx; dst_ctx->initial_pool_size = src_ctx->initial_pool_size; - AVD3D11VAFramesContext *dst_hwctx = dst_ctx->hwctx; + dst_hwctx = dst_ctx->hwctx; dst_hwctx->texture_infos = av_calloc(src_hwctx->nb_surfaces, sizeof(*dst_hwctx->texture_infos)); if (!dst_hwctx->texture_infos) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 56d03aa4cd..95a68e62c5 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -1213,7 +1213,7 @@ static int vaapi_map_from_drm(AVHWFramesContext *src_fc, AVFrame *dst, if (!use_prime2 || vas != VA_STATUS_SUCCESS) { int k; - unsigned long buffer_handle; + uintptr_t buffer_handle; VASurfaceAttribExternalBuffers buffer_desc; VASurfaceAttrib buffer_attrs[2] = { { diff --git a/libavutil/iamf.c b/libavutil/iamf.c index 84bed5a45e..14f49cba93 100644 --- a/libavutil/iamf.c +++ b/libavutil/iamf.c @@ -66,15 +66,15 @@ child_type *av_iamf_ ## parent_name ## _add_ ## child_name(parent_type *parent_n static const AVOption mix_gain_options[] = { { "subblock_duration", "set subblock_duration", OFFSET(subblock_duration), AV_OPT_TYPE_INT, {.i64 = 1 }, 1, UINT_MAX, FLAGS }, { "animation_type", "set animation_type", OFFSET(animation_type), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, FLAGS }, - { "start_point_value", "set start_point_value", OFFSET(animation_type), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, -128.0, 128.0, FLAGS }, - { "end_point_value", "set end_point_value", OFFSET(animation_type), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, -128.0, 128.0, FLAGS }, - { "control_point_value", "set control_point_value", OFFSET(animation_type), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, -128.0, 128.0, FLAGS }, - { "control_point_relative_time", "set control_point_relative_time", OFFSET(animation_type), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, 0.0, 1.0, FLAGS }, + { "start_point_value", "set start_point_value", OFFSET(start_point_value), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, -128.0, 128.0, FLAGS }, + { "end_point_value", "set end_point_value", OFFSET(end_point_value), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, -128.0, 128.0, FLAGS }, + { "control_point_value", "set control_point_value", OFFSET(control_point_value), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, -128.0, 128.0, FLAGS }, + { "control_point_relative_time", "set control_point_relative_time", OFFSET(control_point_relative_time), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, 0.0, 1.0, FLAGS }, { NULL }, }; static const AVClass mix_gain_class = { - .class_name = "AVIAMFSubmixElement", + .class_name = "AVIAMFMixGain", .item_name = av_default_item_name, .version = LIBAVUTIL_VERSION_INT, .option = mix_gain_options, diff --git a/libavutil/iamf.h b/libavutil/iamf.h index 93785d9fec..1fa73893cd 100644 --- a/libavutil/iamf.h +++ b/libavutil/iamf.h @@ -37,20 +37,29 @@ #include "rational.h" /** + * @defgroup lavu_iamf Immersive Audio Model and Formats + * @ingroup lavu_audio + * + * Immersive Audio Model and Formats related functions and defines + * * @defgroup lavu_iamf_params Parameter Definition + * @ingroup lavu_iamf * @{ * Parameters as defined in section 3.6.1 and 3.8 of IAMF. * @} + * * @defgroup lavu_iamf_audio Audio Element + * @ingroup lavu_iamf * @{ * Audio Elements as defined in section 3.6 of IAMF. * @} + * * @defgroup lavu_iamf_mix Mix Presentation + * @ingroup lavu_iamf * @{ * Mix Presentations as defined in section 3.7 of IAMF. * @} * - * @} * @addtogroup lavu_iamf_params * @{ */ @@ -673,6 +682,7 @@ AVIAMFSubmixLayout *av_iamf_submix_add_layout(AVIAMFSubmix *submix); * upon return, *mix_presentation will be set to NULL. */ void av_iamf_mix_presentation_free(AVIAMFMixPresentation **mix_presentation); + /** * @} */ diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c index 1e15f7c920..b5413aa419 100644 --- a/libavutil/imgutils.c +++ b/libavutil/imgutils.c @@ -298,7 +298,7 @@ int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enu stride = 8LL*w; stride += 128*8; - if ((int)w<=0 || (int)h<=0 || stride >= INT_MAX || stride*(uint64_t)(h+128) >= INT_MAX) { + if (w==0 || h==0 || w > INT32_MAX || h > INT32_MAX || stride >= INT_MAX || stride*(h + 128ULL) >= INT_MAX) { av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\n", w, h); return AVERROR(EINVAL); } diff --git a/libavutil/ppc/cpu.c b/libavutil/ppc/cpu.c index bc8bb5f47c..2b13cda662 100644 --- a/libavutil/ppc/cpu.c +++ b/libavutil/ppc/cpu.c @@ -27,7 +27,7 @@ #if HAVE_UNISTD_H #include #endif -#elif defined(__OpenBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) #include #include #include @@ -56,8 +56,8 @@ int ff_get_cpu_flags_ppc(void) if (result == VECTORTYPE_ALTIVEC) return AV_CPU_FLAG_ALTIVEC; return 0; -#elif defined(__APPLE__) || defined(__OpenBSD__) -#ifdef __OpenBSD__ +#elif defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) +#if defined(__NetBSD__) || defined(__OpenBSD__) int sels[2] = {CTL_MACHDEP, CPU_ALTIVEC}; #else int sels[2] = {CTL_HW, HW_VECTORUNIT}; diff --git a/libavutil/slicethread.c b/libavutil/slicethread.c index 115b099736..e6b82e31b6 100644 --- a/libavutil/slicethread.c +++ b/libavutil/slicethread.c @@ -102,6 +102,7 @@ int avpriv_slicethread_create(AVSliceThread **pctx, void *priv, { AVSliceThread *ctx; int nb_workers, i; + int ret; av_assert0(nb_threads >= 0); if (!nb_threads) { @@ -135,16 +136,37 @@ int avpriv_slicethread_create(AVSliceThread **pctx, void *priv, atomic_init(&ctx->first_job, 0); atomic_init(&ctx->current_job, 0); - pthread_mutex_init(&ctx->done_mutex, NULL); - pthread_cond_init(&ctx->done_cond, NULL); + ret = pthread_mutex_init(&ctx->done_mutex, NULL); + if (ret) { + av_freep(&ctx->workers); + av_freep(pctx); + return AVERROR(ret); + } + ret = pthread_cond_init(&ctx->done_cond, NULL); + if (ret) { + ctx->nb_threads = main_func ? 0 : 1; + avpriv_slicethread_free(pctx); + return AVERROR(ret); + } ctx->done = 0; for (i = 0; i < nb_workers; i++) { WorkerContext *w = &ctx->workers[i]; int ret; w->ctx = ctx; - pthread_mutex_init(&w->mutex, NULL); - pthread_cond_init(&w->cond, NULL); + ret = pthread_mutex_init(&w->mutex, NULL); + if (ret) { + ctx->nb_threads = main_func ? i : i + 1; + avpriv_slicethread_free(pctx); + return AVERROR(ret); + } + ret = pthread_cond_init(&w->cond, NULL); + if (ret) { + pthread_mutex_destroy(&w->mutex); + ctx->nb_threads = main_func ? i : i + 1; + avpriv_slicethread_free(pctx); + return AVERROR(ret); + } pthread_mutex_lock(&w->mutex); w->done = 0; diff --git a/libavutil/tests/base64.c b/libavutil/tests/base64.c index 400e01cefe..66d0fdc1fc 100644 --- a/libavutil/tests/base64.c +++ b/libavutil/tests/base64.c @@ -64,6 +64,16 @@ static int test_encode_decode(const uint8_t *data, unsigned int data_size, printf("Failed: decode to NULL buffer\n"); return 1; } + if (data_size > 0 && (data2_size = av_base64_decode(data2, encoded, data_size - 1)) != data_size - 1) { + printf("Failed: out of array write\n" + "Encoded:\n%s\n", encoded); + return 1; + } + if (data_size > 1 && (data2_size = av_base64_decode(data2, encoded, data_size - 2)) != data_size - 2) { + printf("Failed: out of array write\n" + "Encoded:\n%s\n", encoded); + return 1; + } if (strlen(encoded)) { char *end = strchr(encoded, '='); if (!end) diff --git a/libavutil/tests/dict.c b/libavutil/tests/dict.c index bececefb31..d60081889f 100644 --- a/libavutil/tests/dict.c +++ b/libavutil/tests/dict.c @@ -148,12 +148,15 @@ int main(void) //valgrind sensible test printf("\nTesting av_dict_set() with existing AVDictionaryEntry.key as key\n"); - av_dict_set(&dict, "key", "old", 0); + if (av_dict_set(&dict, "key", "old", 0) < 0) + return 1; e = av_dict_get(dict, "key", NULL, 0); - av_dict_set(&dict, e->key, "new val OK", 0); + if (av_dict_set(&dict, e->key, "new val OK", 0) < 0) + return 1; e = av_dict_get(dict, "key", NULL, 0); printf("%s\n", e->value); - av_dict_set(&dict, e->key, e->value, 0); + if (av_dict_set(&dict, e->key, e->value, 0) < 0) + return 1; e = av_dict_get(dict, "key", NULL, 0); printf("%s\n", e->value); av_dict_free(&dict); diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c index ccf3a54f96..281ad0dc35 100644 --- a/libavutil/tests/opt.c +++ b/libavutil/tests/opt.c @@ -264,6 +264,7 @@ int main(void) { TestContext test_ctx = { 0 }; char *buf; + int ret; test_ctx.class = &test_class; av_log_set_level(AV_LOG_QUIET); @@ -274,8 +275,10 @@ int main(void) av_opt_free(&test_ctx); memset(&test_ctx, 0, sizeof(test_ctx)); test_ctx.class = &test_class; - av_set_options_string(&test_ctx, buf, "=", ","); + ret = av_set_options_string(&test_ctx, buf, "=", ","); av_free(buf); + if (ret < 0) + printf("Error ret '%d'\n", ret); if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) { printf("%s\n", buf); av_free(buf); diff --git a/libavutil/timecode.c b/libavutil/timecode.c index bd879bd3cc..f454466f97 100644 --- a/libavutil/timecode.c +++ b/libavutil/timecode.c @@ -61,8 +61,8 @@ uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum) framenum = av_timecode_adjust_ntsc_framenum2(framenum, tc->fps); ff = framenum % fps; ss = framenum / fps % 60; - mm = framenum / (fps*60) % 60; - hh = framenum / (fps*3600) % 24; + mm = framenum / (fps*60LL) % 60; + hh = framenum / (fps*3600LL) % 24; return av_timecode_get_smpte(tc->rate, drop, hh, mm, ss, ff); } @@ -100,11 +100,12 @@ uint32_t av_timecode_get_smpte(AVRational rate, int drop, int hh, int mm, int ss return tc; } -char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum) +char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum_arg) { int fps = tc->fps; int drop = tc->flags & AV_TIMECODE_FLAG_DROPFRAME; int hh, mm, ss, ff, ff_len, neg = 0; + int64_t framenum = framenum_arg; framenum += tc->start; if (drop) diff --git a/libavutil/timestamp.c b/libavutil/timestamp.c index 2a3e3012a4..6c231a517d 100644 --- a/libavutil/timestamp.c +++ b/libavutil/timestamp.c @@ -24,7 +24,7 @@ char *av_ts_make_time_string2(char *buf, int64_t ts, AVRational tb) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS"); } else { double val = av_q2d(tb) * ts; - double log = floor(log10(fabs(val))); + double log = (fpclassify(val) == FP_ZERO ? -INFINITY : floor(log10(fabs(val)))); int precision = (isfinite(log) && log < 0) ? -log + 5 : 6; int last = snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.*f", precision, val); last = FFMIN(last, AV_TS_MAX_STRING_SIZE - 1) - 1; diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h index 868a30b532..1370a084c9 100644 --- a/libavutil/wchar_filename.h +++ b/libavutil/wchar_filename.h @@ -57,7 +57,7 @@ static inline int wchartocp(unsigned int code_page, const wchar_t *filename_w, errno = EINVAL; return -1; } - *filename = (char*)av_malloc_array(num_chars, sizeof *filename); + *filename = (char *)av_malloc_array(num_chars, sizeof **filename); if (!*filename) { errno = ENOMEM; return -1; diff --git a/libswscale/loongarch/swscale_init_loongarch.c b/libswscale/loongarch/swscale_init_loongarch.c index 53e4f970b6..51bfdd56de 100644 --- a/libswscale/loongarch/swscale_init_loongarch.c +++ b/libswscale/loongarch/swscale_init_loongarch.c @@ -93,60 +93,64 @@ av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsContext *c) int cpu_flags = av_get_cpu_flags(); #if HAVE_LASX if (have_lasx(cpu_flags)) { - switch (c->dstFormat) { - case AV_PIX_FMT_RGB24: - return yuv420_rgb24_lasx; - case AV_PIX_FMT_BGR24: - return yuv420_bgr24_lasx; - case AV_PIX_FMT_RGBA: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { - break; - } else - return yuv420_rgba32_lasx; - case AV_PIX_FMT_ARGB: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { - break; - } else - return yuv420_argb32_lasx; - case AV_PIX_FMT_BGRA: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { - break; - } else - return yuv420_bgra32_lasx; - case AV_PIX_FMT_ABGR: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { - break; - } else - return yuv420_abgr32_lasx; + if (c->srcFormat == AV_PIX_FMT_YUV420P) { + switch (c->dstFormat) { + case AV_PIX_FMT_RGB24: + return yuv420_rgb24_lasx; + case AV_PIX_FMT_BGR24: + return yuv420_bgr24_lasx; + case AV_PIX_FMT_RGBA: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_rgba32_lasx; + case AV_PIX_FMT_ARGB: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_argb32_lasx; + case AV_PIX_FMT_BGRA: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_bgra32_lasx; + case AV_PIX_FMT_ABGR: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_abgr32_lasx; + } } } #endif // #if HAVE_LASX if (have_lsx(cpu_flags)) { - switch (c->dstFormat) { - case AV_PIX_FMT_RGB24: - return yuv420_rgb24_lsx; - case AV_PIX_FMT_BGR24: - return yuv420_bgr24_lsx; - case AV_PIX_FMT_RGBA: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { - break; - } else - return yuv420_rgba32_lsx; - case AV_PIX_FMT_ARGB: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { - break; - } else - return yuv420_argb32_lsx; - case AV_PIX_FMT_BGRA: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { - break; - } else - return yuv420_bgra32_lsx; - case AV_PIX_FMT_ABGR: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { - break; - } else - return yuv420_abgr32_lsx; + if (c->srcFormat == AV_PIX_FMT_YUV420P) { + switch (c->dstFormat) { + case AV_PIX_FMT_RGB24: + return yuv420_rgb24_lsx; + case AV_PIX_FMT_BGR24: + return yuv420_bgr24_lsx; + case AV_PIX_FMT_RGBA: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_rgba32_lsx; + case AV_PIX_FMT_ARGB: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_argb32_lsx; + case AV_PIX_FMT_BGRA: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_bgra32_lsx; + case AV_PIX_FMT_ABGR: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_abgr32_lsx; + } } } return NULL; diff --git a/libswscale/loongarch/yuv2rgb_lasx.c b/libswscale/loongarch/yuv2rgb_lasx.c index 64e434f50c..0ce553005a 100644 --- a/libswscale/loongarch/yuv2rgb_lasx.c +++ b/libswscale/loongarch/yuv2rgb_lasx.c @@ -82,8 +82,8 @@ #define YUV2RGB_RES \ m_y1 = __lasx_xvldrepl_d(py_1, 0); \ m_y2 = __lasx_xvldrepl_d(py_2, 0); \ - m_u = __lasx_xvldrepl_d(pu, 0); \ - m_v = __lasx_xvldrepl_d(pv, 0); \ + m_u = __lasx_xvldrepl_w(pu, 0); \ + m_v = __lasx_xvldrepl_w(pv, 0); \ m_y1 = __lasx_xvilvl_d(m_y2, m_y1); \ m_u = __lasx_xvilvl_b(m_u, m_u); \ m_v = __lasx_xvilvl_b(m_v, m_v); \ diff --git a/libswscale/output.c b/libswscale/output.c index 8849a3201a..4ca6be8977 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -664,7 +664,7 @@ yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2], if (c->dither == SWS_DITHER_ED) { int err = 0; - int acc = 0; + unsigned acc = 0; for (i = 0; i < dstW; i +=2) { int Y; @@ -686,7 +686,8 @@ yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2], c->dither_error[0][i] = err; } else { for (i = 0; i < dstW; i += 8) { - int Y, acc = 0; + int Y; + unsigned acc = 0; Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19; accumulate_bit(acc, Y + d128[0]); @@ -721,7 +722,7 @@ yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0, if (c->dither == SWS_DITHER_ED) { int err = 0; - int acc = 0; + unsigned acc = 0; for (i = 0; i < dstW; i +=2) { int Y; @@ -743,7 +744,7 @@ yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0, c->dither_error[0][i] = err; } else { for (i = 0; i < dstW; i += 8) { - int acc = 0; + unsigned acc = 0; accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]); accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]); accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]); @@ -1059,8 +1060,8 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter, for (i = 0; i < ((dstW + 1) >> 1); i++) { int j; - int Y1 = -0x40000000; - int Y2 = -0x40000000; + unsigned Y1 = -0x40000000; + unsigned Y2 = -0x40000000; int U = -(128 << 23); // 19 int V = -(128 << 23); int R, G, B; @@ -1088,9 +1089,9 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter, } // 8 bits: 12+15=27; 16 bits: 12+19=31 - Y1 >>= 14; // 10 + Y1 = (int)Y1 >> 14; // 10 Y1 += 0x10000; - Y2 >>= 14; + Y2 = (int)Y2 >> 14; Y2 += 0x10000; U >>= 14; V >>= 14; @@ -1109,20 +1110,20 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter, B = U * c->yuv2rgb_u2b_coeff; // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits - output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16)); - output_pixel(&dest[1], av_clip_uintp2((( G + Y1) >> 14) + (1<<15), 16)); - output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16)); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[5], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); dest += 8; } else { - output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[4], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); dest += 6; } } @@ -1150,8 +1151,8 @@ yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2], av_assert2(uvalpha <= 4096U); for (i = 0; i < ((dstW + 1) >> 1); i++) { - int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14; - int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14; + unsigned Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14; + unsigned Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14; int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14; int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14; int R, G, B; @@ -1175,20 +1176,20 @@ yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2], A2 += 1 << 13; } - output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16)); - output_pixel(&dest[1], av_clip_uintp2((( G + Y1) >> 14) + (1<<15), 16)); - output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16)); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[5], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); dest += 8; } else { - output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[4], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); dest += 6; } } @@ -1207,8 +1208,8 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, if (uvalpha < 2048) { for (i = 0; i < ((dstW + 1) >> 1); i++) { - int Y1 = (buf0[i * 2] ) >> 2; - int Y2 = (buf0[i * 2 + 1]) >> 2; + SUINT Y1 = (buf0[i * 2] ) >> 2; + SUINT Y2 = (buf0[i * 2 + 1]) >> 2; int U = (ubuf0[i] - (128 << 11)) >> 2; int V = (vbuf0[i] - (128 << 11)) >> 2; int R, G, B; @@ -1221,8 +1222,8 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, Y2 += (1 << 13) - (1 << 29); if (hasAlpha) { - A1 = abuf0[i * 2 ] << 11; - A2 = abuf0[i * 2 + 1] << 11; + A1 = abuf0[i * 2 ] * (1 << 11); + A2 = abuf0[i * 2 + 1] * (1 << 11); A1 += 1 << 13; A2 += 1 << 13; @@ -1232,20 +1233,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; B = U * c->yuv2rgb_u2b_coeff; - output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16)); - output_pixel(&dest[1], av_clip_uintp2((( G + Y1) >> 14) + (1<<15), 16)); - output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16)); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[5], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); dest += 8; } else { - output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[4], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); dest += 6; } } @@ -1253,8 +1254,8 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; int A1 = 0xffff<<14, A2 = 0xffff<<14; for (i = 0; i < ((dstW + 1) >> 1); i++) { - int Y1 = (buf0[i * 2] ) >> 2; - int Y2 = (buf0[i * 2 + 1]) >> 2; + SUINT Y1 = (buf0[i * 2] ) >> 2; + SUINT Y2 = (buf0[i * 2 + 1]) >> 2; int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3; int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3; int R, G, B; @@ -1267,8 +1268,8 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, Y2 += (1 << 13) - (1 << 29); if (hasAlpha) { - A1 = abuf0[i * 2 ] << 11; - A2 = abuf0[i * 2 + 1] << 11; + A1 = abuf0[i * 2 ] * (1 << 11); + A2 = abuf0[i * 2 + 1] * (1 << 11); A1 += 1 << 13; A2 += 1 << 13; @@ -1278,20 +1279,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; B = U * c->yuv2rgb_u2b_coeff; - output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16)); - output_pixel(&dest[1], av_clip_uintp2((( G + Y1) >> 14) + (1<<15), 16)); - output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16)); + output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16)); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[5], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); dest += 8; } else { - output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[4], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); - output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); + output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); dest += 6; } } @@ -1351,9 +1352,9 @@ yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter, B = U * c->yuv2rgb_u2b_coeff; // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit - output_pixel(&dest[0], av_clip_uintp2(((R_B + Y)>>14) + (1<<15), 16)); - output_pixel(&dest[1], av_clip_uintp2((( G + Y)>>14) + (1<<15), 16)); - output_pixel(&dest[2], av_clip_uintp2(((B_R + Y)>>14) + (1<<15), 16)); + output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + (unsigned)Y)>>14) + (1<<15), 16)); + output_pixel(&dest[1], av_clip_uintp2(((int)( G + (unsigned)Y)>>14) + (1<<15), 16)); + output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + (unsigned)Y)>>14) + (1<<15), 16)); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14); dest += 4; @@ -1429,7 +1430,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, if (uvalpha < 2048) { for (i = 0; i < dstW; i++) { - int Y = (buf0[i]) >> 2; + SUINT Y = (buf0[i]) >> 2; int U = (ubuf0[i] - (128 << 11)) >> 2; int V = (vbuf0[i] - (128 << 11)) >> 2; int R, G, B; @@ -1439,7 +1440,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, Y += (1 << 13) - (1 << 29); if (hasAlpha) { - A = abuf0[i] << 11; + A = abuf0[i] * (1 << 11); A += 1 << 13; } @@ -1448,9 +1449,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; B = U * c->yuv2rgb_u2b_coeff; - output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16)); - output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16)); - output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16)); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14); dest += 4; @@ -1462,7 +1463,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; int A = 0xffff<<14; for (i = 0; i < dstW; i++) { - int Y = (buf0[i] ) >> 2; + SUINT Y = (buf0[i] ) >> 2; int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3; int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3; int R, G, B; @@ -1472,7 +1473,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, Y += (1 << 13) - (1 << 29); if (hasAlpha) { - A = abuf0[i] << 11; + A = abuf0[i] * (1 << 11); A += 1 << 13; } @@ -1481,9 +1482,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; B = U * c->yuv2rgb_u2b_coeff; - output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16)); - output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16)); - output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16)); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14); dest += 4; @@ -1925,9 +1926,9 @@ static av_always_inline void yuv2rgb_write_full(SwsContext *c, Y -= c->yuv2rgb_y_offset; Y *= c->yuv2rgb_y_coeff; Y += 1 << 21; - R = (unsigned)Y + V*c->yuv2rgb_v2r_coeff; - G = (unsigned)Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff; - B = (unsigned)Y + U*c->yuv2rgb_u2b_coeff; + R = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2r_coeff; + G = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2g_coeff + U*(unsigned)c->yuv2rgb_u2g_coeff; + B = (unsigned)Y + U*(unsigned)c->yuv2rgb_u2b_coeff; if ((R | G | B) & 0xC0000000) { R = av_clip_uintp2(R, 30); G = av_clip_uintp2(G, 30); diff --git a/libswscale/ppc/yuv2rgb_altivec.c b/libswscale/ppc/yuv2rgb_altivec.c index 5e1033a973..8b0a93796f 100644 --- a/libswscale/ppc/yuv2rgb_altivec.c +++ b/libswscale/ppc/yuv2rgb_altivec.c @@ -284,7 +284,7 @@ static inline void cvtyuvtoRGB(SwsContext *c, vector signed short Y, * ------------------------------------------------------------------------------ */ -#if !HAVE_VSX +#if !HAVE_VEC_XL static inline vector unsigned char vec_xl(signed long long offset, const ubyte *addr) { const vector unsigned char *v_addr = (const vector unsigned char *) (addr + offset); @@ -292,7 +292,7 @@ static inline vector unsigned char vec_xl(signed long long offset, const ubyte * return (vector unsigned char) vec_perm(v_addr[0], v_addr[1], align_perm); } -#endif /* !HAVE_VSX */ +#endif /* !HAVE_VEC_XL */ #define DEFCSP420_CVT(name, out_pixels) \ static int altivec_ ## name(SwsContext *c, const unsigned char **in, \ diff --git a/libswscale/slice.c b/libswscale/slice.c index db1c696727..9dff91c18d 100644 --- a/libswscale/slice.c +++ b/libswscale/slice.c @@ -59,7 +59,7 @@ static int alloc_lines(SwsSlice *s, int size, int width) for (j = 0; j < n; ++j) { // chroma plane line U and V are expected to be contiguous in memory // by mmx vertical scaler code - s->plane[i].line[j] = av_malloc(size * 2 + 32); + s->plane[i].line[j] = av_mallocz(size * 2 + 32); if (!s->plane[i].line[j]) { free_lines(s); return AVERROR(ENOMEM); diff --git a/libswscale/swscale.c b/libswscale/swscale.c index fe0e74f871..87314c2edb 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -223,7 +223,7 @@ static void lumRangeFromJpeg16_c(int16_t *_dst, int width) int i; int32_t *dst = (int32_t *) _dst; for (i = 0; i < width; i++) - dst[i] = (dst[i]*(14071/4) + (33561947<<4)/4)>>12; + dst[i] = ((int)(dst[i]*(14071U/4) + (33561947<<4)/4)) >> 12; } @@ -1172,7 +1172,7 @@ int sws_receive_slice(struct SwsContext *c, unsigned int slice_start, } for (int i = 0; i < FF_ARRAY_ELEMS(dst); i++) { - ptrdiff_t offset = c->frame_dst->linesize[i] * (slice_start >> c->chrDstVSubSample); + ptrdiff_t offset = c->frame_dst->linesize[i] * (ptrdiff_t)(slice_start >> c->chrDstVSubSample); dst[i] = FF_PTR_ADD(c->frame_dst->data[i], offset); } @@ -1233,7 +1233,7 @@ void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, for (int i = 0; i < FF_ARRAY_ELEMS(dst) && parent->frame_dst->data[i]; i++) { const int vshift = (i == 1 || i == 2) ? c->chrDstVSubSample : 0; const ptrdiff_t offset = parent->frame_dst->linesize[i] * - ((slice_start + parent->dst_slice_start) >> vshift); + (ptrdiff_t)((slice_start + parent->dst_slice_start) >> vshift); dst[i] = parent->frame_dst->data[i] + offset; } diff --git a/libswscale/utils.c b/libswscale/utils.c index ab8a68e241..54bbd519af 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -564,7 +564,7 @@ static av_cold int initFilter(int16_t **outFilter, int32_t **filterPos, filter[i * filterSize + j] = coeff; xx++; } - xDstInSrc += 2 * xInc; + xDstInSrc += 2LL * xInc; } } diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c index ff16398988..fff8bb4396 100644 --- a/libswscale/x86/swscale.c +++ b/libswscale/x86/swscale.c @@ -649,7 +649,7 @@ switch(c->dstBpc){ \ } -#define INPUT_PLANER_RGB_A_FUNC_CASE(fmt, name, opt) \ +#define INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(fmt, name, opt) \ case fmt: \ c->readAlpPlanar = ff_planar_##name##_to_a_##opt; @@ -672,15 +672,15 @@ switch(c->dstBpc){ \ break; #define INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \ - INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##LE, name##le, opt) \ + INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##LE, name##le, opt) \ INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \ - INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##BE, name##be, opt) \ + INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##BE, name##be, opt) \ INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##BE, name##be, opt) #define INPUT_PLANER_RGBAXX_UVA_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \ - INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##LE, name##le, opt) \ + INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##LE, name##le, opt) \ INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \ - INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##BE, name##be, opt) \ + INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##BE, name##be, opt) \ INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##BE, name##be, opt) #define INPUT_PLANER_RGBAXX_YUV_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \ @@ -696,7 +696,7 @@ switch(c->dstBpc){ \ INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##BE, name##be, opt) #define INPUT_PLANER_RGB_YUVA_ALL_CASES(opt) \ - INPUT_PLANER_RGB_A_FUNC_CASE( AV_PIX_FMT_GBRAP, rgb, opt) \ + INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(AV_PIX_FMT_GBRAP, rgb, opt) \ INPUT_PLANER_RGB_YUV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, opt) \ INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, opt) \ INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, opt) \ @@ -708,7 +708,7 @@ switch(c->dstBpc){ \ if (EXTERNAL_SSE2(cpu_flags)) { switch (c->srcFormat) { - INPUT_PLANER_RGB_A_FUNC_CASE( AV_PIX_FMT_GBRAP, rgb, sse2); + INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(AV_PIX_FMT_GBRAP, rgb, sse2); INPUT_PLANER_RGB_UV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, sse2); INPUT_PLANER_RGBXX_UV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, sse2); INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, sse2); diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c index 0a84b662f9..d57a87ce07 100644 --- a/libswscale/yuv2rgb.c +++ b/libswscale/yuv2rgb.c @@ -831,7 +831,7 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], cbu = (cbu * contrast * saturation) >> 32; cgu = (cgu * contrast * saturation) >> 32; cgv = (cgv * contrast * saturation) >> 32; - oy -= 256 * brightness; + oy -= 256LL * brightness; c->uOffset = 0x0400040004000400LL; c->vOffset = 0x0400040004000400LL; diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak index 30021efbcd..4095a4b51a 100644 --- a/tests/fate/enc_external.mak +++ b/tests/fate/enc_external.mak @@ -12,10 +12,5 @@ FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 HEVC, MOV, LIBX264_HDR10 HEVC_DEMUXER H fate-libx264-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ mp4 "-c:v libx264" "-show_frames -show_entries frame=side_data_list -of flat" -# test for x265 MDCV and CLL passthrough during encoding -FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX265 HEVC, MOV, HEVC_DEMUXER) += fate-libx265-hdr10 -fate-libx265-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ - mp4 "-c:v libx265" "-show_frames -show_entries frame=side_data_list -of flat" - FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes) fate-enc-external: $(FATE_ENC_EXTERNAL-yes) diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak index 3c549b265e..077104c713 100644 --- a/tests/fate/ffmpeg.mak +++ b/tests/fate/ffmpeg.mak @@ -16,10 +16,10 @@ fate-ffmpeg-filter_colorkey: CMD = framecrc -auto_conversion_filters -idct simpl FATE_FFMPEG-$(call FILTERFRAMECRC, COLOR) += fate-ffmpeg-lavfi fate-ffmpeg-lavfi: CMD = framecrc -lavfi color=d=1:r=5 -fflags +bitexact -FATE_SAMPLES_FFMPEG-$(call ENCDEC2, MPEG4, RAWVIDEO, AVI, RAWVIDEO_DEMUXER FRAMECRC_MUXER) += fate-force_key_frames -fate-force_key_frames: tests/data/vsynth_lena.yuv +FATE_FFMPEG-$(call ENCDEC2, MPEG4, RAWVIDEO, AVI, RAWVIDEO_DEMUXER FRAMECRC_MUXER) += fate-force_key_frames +fate-force_key_frames: tests/data/vsynth1.yuv fate-force_key_frames: CMD = enc_dec \ - "rawvideo -s 352x288 -pix_fmt yuv420p" tests/data/vsynth_lena.yuv \ + "rawvideo -s 352x288 -pix_fmt yuv420p" tests/data/vsynth1.yuv \ avi "-c mpeg4 -g 240 -qscale 10 -force_key_frames 0.5,0:00:01.5" \ framecrc "" "-skip_frame nokey" @@ -87,12 +87,12 @@ fate-unknown_layout-ac3: CMD = md5 -auto_conversion_filters \ -guess_layout_max 0 -f s32le -ac 1 -ar 44100 -i $(TARGET_PATH)/$(AREF) \ -f ac3 -flags +bitexact -c ac3_fixed -FATE_SAMPLES_FFMPEG-$(call FILTERDEMDEC, AMIX ARESAMPLE SINE, RAWVIDEO, \ +FATE_FFMPEG-$(call FILTERDEMDEC, AMIX ARESAMPLE SINE, RAWVIDEO, \ PCM_S16LE RAWVIDEO, LAVFI_INDEV \ MPEG4_ENCODER AC3_FIXED_ENCODER) \ += fate-shortest -fate-shortest: tests/data/vsynth_lena.yuv -fate-shortest: CMD = framecrc -auto_conversion_filters -f lavfi -i "sine=3000:d=10" -f lavfi -i "sine=1000:d=1" -sws_flags +accurate_rnd+bitexact -fflags +bitexact -flags +bitexact -idct simple -f rawvideo -s 352x288 -pix_fmt yuv420p -i $(TARGET_PATH)/tests/data/vsynth_lena.yuv -filter_complex "[0:a:0][1:a:0]amix=inputs=2[audio]" -map 2:v:0 -map "[audio]" -sws_flags +accurate_rnd+bitexact -fflags +bitexact -flags +bitexact -idct simple -dct fastint -qscale 10 -threads 1 -c:v mpeg4 -c:a ac3_fixed -shortest +fate-shortest: tests/data/vsynth1.yuv +fate-shortest: CMD = framecrc -auto_conversion_filters -f lavfi -i "sine=3000:d=10" -f lavfi -i "sine=1000:d=1" -sws_flags +accurate_rnd+bitexact -fflags +bitexact -flags +bitexact -idct simple -f rawvideo -s 352x288 -pix_fmt yuv420p -i $(TARGET_PATH)/tests/data/vsynth1.yuv -filter_complex "[0:a:0][1:a:0]amix=inputs=2[audio]" -map 2:v:0 -map "[audio]" -sws_flags +accurate_rnd+bitexact -fflags +bitexact -flags +bitexact -idct simple -dct fastint -qscale 10 -threads 1 -c:v mpeg4 -c:a ac3_fixed -shortest # test interleaving video with a sparse subtitle stream FATE_SAMPLES_FFMPEG-$(call ALLYES, COLOR_FILTER, VOBSUB_DEMUXER, MATROSKA_DEMUXER,, \ @@ -240,24 +240,24 @@ FATE_SAMPLES_FFMPEG-$(call FRAMECRC, MOV, , SETTS_BSF) += fate-ffmpeg-bsf-input # Test behaviour when a complex filtergraph returns EOF on one of its inputs, # but other inputs are still active. # cf. #10803 -fate-ffmpeg-filter-in-eof: tests/data/vsynth_lena.yuv -fate-ffmpeg-filter-in-eof: CMD = framecrc \ - -f rawvideo -s 352x288 -pix_fmt yuv420p -t 1 -i $(TARGET_PATH)/tests/data/vsynth_lena.yuv \ - -f rawvideo -s 352x288 -pix_fmt yuv420p -t 1 -i $(TARGET_PATH)/tests/data/vsynth_lena.yuv \ +fate-ffmpeg-filter-in-eof: tests/data/vsynth1.yuv +fate-ffmpeg-filter-in-eof: CMD = framecrc \ + -f rawvideo -s 352x288 -pix_fmt yuv420p -t 1 -i $(TARGET_PATH)/tests/data/vsynth1.yuv \ + -f rawvideo -s 352x288 -pix_fmt yuv420p -t 1 -i $(TARGET_PATH)/tests/data/vsynth1.yuv \ -filter_complex "[0][1]concat" -c:v rawvideo FATE_FFMPEG-$(call FRAMECRC, RAWVIDEO, RAWVIDEO, CONCAT_FILTER) += fate-ffmpeg-filter-in-eof # Test termination on streamcopy with -t as an output option. -fate-ffmpeg-streamcopy-t: tests/data/vsynth_lena.yuv +fate-ffmpeg-streamcopy-t: tests/data/vsynth1.yuv fate-ffmpeg-streamcopy-t: CMP = null -fate-ffmpeg-streamcopy-t: CMD = ffmpeg \ - -stream_loop -1 -f rawvideo -s 352x288 -pix_fmt yuv420p -i $(TARGET_PATH)/tests/data/vsynth_lena.yuv \ +fate-ffmpeg-streamcopy-t: CMD = ffmpeg \ + -stream_loop -1 -f rawvideo -s 352x288 -pix_fmt yuv420p -i $(TARGET_PATH)/tests/data/vsynth1.yuv \ -c copy -f null -t 1 - FATE_FFMPEG-$(call REMUX, RAWVIDEO) += fate-ffmpeg-streamcopy-t # Test loopback decoding and passing the output to a complex graph. -fate-ffmpeg-loopback-decoding: tests/data/vsynth_lena.yuv +fate-ffmpeg-loopback-decoding: tests/data/vsynth1.yuv fate-ffmpeg-loopback-decoding: CMD = transcode \ - "rawvideo -s 352x288 -pix_fmt yuv420p" $(TARGET_PATH)/tests/data/vsynth_lena.yuv nut \ + "rawvideo -s 352x288 -pix_fmt yuv420p" $(TARGET_PATH)/tests/data/vsynth1.yuv nut \ "-map 0:v:0 -c:v mpeg2video -f null - -flags +bitexact -idct simple -threads $$threads -dec 0:0 -filter_complex '[0:v][dec:0]hstack[stack]' -map '[stack]' -c:v ffv1" "" FATE_FFMPEG-$(call ENCDEC2, MPEG2VIDEO, FFV1, NUT, HSTACK_FILTER PIPE_PROTOCOL FRAMECRC_MUXER) += fate-ffmpeg-loopback-decoding diff --git a/tests/fate/vvc.mak b/tests/fate/vvc.mak index f5a45cc4ca..d1bc8ef935 100644 --- a/tests/fate/vvc.mak +++ b/tests/fate/vvc.mak @@ -9,7 +9,6 @@ VVC_SAMPLES_10BIT = \ BUMP_A_2 \ DCI_A_3 \ HRD_A_3 \ - OPI_B_3 \ PHSH_B_1 \ POC_A_1 \ PPS_B_1 \ @@ -21,7 +20,6 @@ VVC_SAMPLES_10BIT = \ STILL_B_1 \ SUBPIC_A_3 \ TILE_A_2 \ - VPS_A_3 \ WP_A_3 \ WPP_A_3 \ WRAP_A_4 \ @@ -31,6 +29,8 @@ VVC_SAMPLES_444_10BIT = \ # not tested: # BOUNDARY_A_3 (too big) +# OPI_B_3 (Inter layer ref support needed) +# VPS_A_3 (Inter layer ref support needed) FATE_VVC_VARS := 8BIT 10BIT 444_10BIT $(foreach VAR,$(FATE_VVC_VARS), $(eval VVC_TESTS_$(VAR) := $(addprefix fate-vvc-conformance-, $(VVC_SAMPLES_$(VAR))))) diff --git a/tests/ref/fate/ffmpeg-filter-in-eof b/tests/ref/fate/ffmpeg-filter-in-eof index 77be842408..5b376bd8c3 100644 --- a/tests/ref/fate/ffmpeg-filter-in-eof +++ b/tests/ref/fate/ffmpeg-filter-in-eof @@ -3,53 +3,53 @@ #codec_id 0: rawvideo #dimensions 0: 352x288 #sar 0: 0/1 -0, 0, 0, 1, 152064, 0x07945924 -0, 1, 1, 1, 152064, 0x08472470 -0, 2, 2, 1, 152064, 0x63fde13b -0, 3, 3, 1, 152064, 0x67ba9c55 -0, 4, 4, 1, 152064, 0x8aa34b24 -0, 5, 5, 1, 152064, 0x9fba089e -0, 6, 6, 1, 152064, 0xb040d8e3 -0, 7, 7, 1, 152064, 0x3061ae08 -0, 8, 8, 1, 152064, 0xf5907946 -0, 9, 9, 1, 152064, 0x0ea24935 -0, 10, 10, 1, 152064, 0x7d87276b -0, 11, 11, 1, 152064, 0x122c252b -0, 12, 12, 1, 152064, 0xdb0f3889 -0, 13, 13, 1, 152064, 0x88466739 -0, 14, 14, 1, 152064, 0xca87a583 -0, 15, 15, 1, 152064, 0x34f9da44 -0, 16, 16, 1, 152064, 0x1d4e1646 -0, 17, 17, 1, 152064, 0x29975c2b -0, 18, 18, 1, 152064, 0xbf82aae9 -0, 19, 19, 1, 152064, 0x33c2fd7c -0, 20, 20, 1, 152064, 0xa3c95f44 -0, 21, 21, 1, 152064, 0x5f93bc9d -0, 22, 22, 1, 152064, 0xa6f11b51 -0, 23, 23, 1, 152064, 0x39bc6b45 -0, 24, 24, 1, 152064, 0xfd509e1d -0, 25, 25, 1, 152064, 0x07945924 -0, 26, 26, 1, 152064, 0x08472470 -0, 27, 27, 1, 152064, 0x63fde13b -0, 28, 28, 1, 152064, 0x67ba9c55 -0, 29, 29, 1, 152064, 0x8aa34b24 -0, 30, 30, 1, 152064, 0x9fba089e -0, 31, 31, 1, 152064, 0xb040d8e3 -0, 32, 32, 1, 152064, 0x3061ae08 -0, 33, 33, 1, 152064, 0xf5907946 -0, 34, 34, 1, 152064, 0x0ea24935 -0, 35, 35, 1, 152064, 0x7d87276b -0, 36, 36, 1, 152064, 0x122c252b -0, 37, 37, 1, 152064, 0xdb0f3889 -0, 38, 38, 1, 152064, 0x88466739 -0, 39, 39, 1, 152064, 0xca87a583 -0, 40, 40, 1, 152064, 0x34f9da44 -0, 41, 41, 1, 152064, 0x1d4e1646 -0, 42, 42, 1, 152064, 0x29975c2b -0, 43, 43, 1, 152064, 0xbf82aae9 -0, 44, 44, 1, 152064, 0x33c2fd7c -0, 45, 45, 1, 152064, 0xa3c95f44 -0, 46, 46, 1, 152064, 0x5f93bc9d -0, 47, 47, 1, 152064, 0xa6f11b51 -0, 48, 48, 1, 152064, 0x39bc6b45 -0, 49, 49, 1, 152064, 0xfd509e1d +0, 0, 0, 1, 152064, 0x05b789ef +0, 1, 1, 1, 152064, 0x4bb46551 +0, 2, 2, 1, 152064, 0x9dddf64a +0, 3, 3, 1, 152064, 0x2a8380b0 +0, 4, 4, 1, 152064, 0x4de3b652 +0, 5, 5, 1, 152064, 0xedb5a8e6 +0, 6, 6, 1, 152064, 0xe20f7c23 +0, 7, 7, 1, 152064, 0x5ab58bac +0, 8, 8, 1, 152064, 0x1f1b8026 +0, 9, 9, 1, 152064, 0x91373915 +0, 10, 10, 1, 152064, 0x02344760 +0, 11, 11, 1, 152064, 0x30f5fcd5 +0, 12, 12, 1, 152064, 0xc711ad61 +0, 13, 13, 1, 152064, 0x24eca223 +0, 14, 14, 1, 152064, 0x52a48ddd +0, 15, 15, 1, 152064, 0xa91c0f05 +0, 16, 16, 1, 152064, 0x8e364e18 +0, 17, 17, 1, 152064, 0xb15d38c8 +0, 18, 18, 1, 152064, 0xf25f6acc +0, 19, 19, 1, 152064, 0xf34ddbff +0, 20, 20, 1, 152064, 0xfc7bf570 +0, 21, 21, 1, 152064, 0x9dc72412 +0, 22, 22, 1, 152064, 0x445d1d59 +0, 23, 23, 1, 152064, 0x2f2768ef +0, 24, 24, 1, 152064, 0xce09f9d6 +0, 25, 25, 1, 152064, 0x05b789ef +0, 26, 26, 1, 152064, 0x4bb46551 +0, 27, 27, 1, 152064, 0x9dddf64a +0, 28, 28, 1, 152064, 0x2a8380b0 +0, 29, 29, 1, 152064, 0x4de3b652 +0, 30, 30, 1, 152064, 0xedb5a8e6 +0, 31, 31, 1, 152064, 0xe20f7c23 +0, 32, 32, 1, 152064, 0x5ab58bac +0, 33, 33, 1, 152064, 0x1f1b8026 +0, 34, 34, 1, 152064, 0x91373915 +0, 35, 35, 1, 152064, 0x02344760 +0, 36, 36, 1, 152064, 0x30f5fcd5 +0, 37, 37, 1, 152064, 0xc711ad61 +0, 38, 38, 1, 152064, 0x24eca223 +0, 39, 39, 1, 152064, 0x52a48ddd +0, 40, 40, 1, 152064, 0xa91c0f05 +0, 41, 41, 1, 152064, 0x8e364e18 +0, 42, 42, 1, 152064, 0xb15d38c8 +0, 43, 43, 1, 152064, 0xf25f6acc +0, 44, 44, 1, 152064, 0xf34ddbff +0, 45, 45, 1, 152064, 0xfc7bf570 +0, 46, 46, 1, 152064, 0x9dc72412 +0, 47, 47, 1, 152064, 0x445d1d59 +0, 48, 48, 1, 152064, 0x2f2768ef +0, 49, 49, 1, 152064, 0xce09f9d6 diff --git a/tests/ref/fate/ffmpeg-loopback-decoding b/tests/ref/fate/ffmpeg-loopback-decoding index e535b9060f..ae92f32a37 100644 --- a/tests/ref/fate/ffmpeg-loopback-decoding +++ b/tests/ref/fate/ffmpeg-loopback-decoding @@ -1,57 +1,57 @@ -faefe475118cacc36dff3cab59baa6cf *tests/data/fate/ffmpeg-loopback-decoding.nut -6478832 tests/data/fate/ffmpeg-loopback-decoding.nut +e4e0e27eb8ed99eedc2458d92401c5e4 *tests/data/fate/ffmpeg-loopback-decoding.nut +7435259 tests/data/fate/ffmpeg-loopback-decoding.nut #tb 0: 1/25 #media_type 0: video #codec_id 0: rawvideo #dimensions 0: 704x288 #sar 0: 0/1 -0, 0, 0, 1, 304128, 0xe07dafdd -0, 1, 1, 1, 304128, 0xc5734e5d -0, 2, 2, 1, 304128, 0x855acdcc -0, 3, 3, 1, 304128, 0x4ad94309 -0, 4, 4, 1, 304128, 0x174ebea3 -0, 5, 5, 1, 304128, 0xdb416da6 -0, 6, 6, 1, 304128, 0x72442b79 -0, 7, 7, 1, 304128, 0x00ddf9ed -0, 8, 8, 1, 304128, 0xe7e7a773 -0, 9, 9, 1, 304128, 0x7df26501 -0, 10, 10, 1, 304128, 0x4f5a3eb3 -0, 11, 11, 1, 304128, 0x1ad35b6c -0, 12, 12, 1, 304128, 0xec8e6f56 -0, 13, 13, 1, 304128, 0xb237e0ef -0, 14, 14, 1, 304128, 0x55b26ce2 -0, 15, 15, 1, 304128, 0x22920436 -0, 16, 16, 1, 304128, 0x54eea0c0 -0, 17, 17, 1, 304128, 0x17113686 -0, 18, 18, 1, 304128, 0xeb9ae1af -0, 19, 19, 1, 304128, 0x1ba09d4c -0, 20, 20, 1, 304128, 0x0100748f -0, 21, 21, 1, 304128, 0xcc914570 -0, 22, 22, 1, 304128, 0x9bc21952 -0, 23, 23, 1, 304128, 0xc118d0af -0, 24, 24, 1, 304128, 0x7e4b2df0 -0, 25, 25, 1, 304128, 0x1078bff2 -0, 26, 26, 1, 304128, 0xeedbeda1 -0, 27, 27, 1, 304128, 0x35ac0a1b -0, 28, 28, 1, 304128, 0x3644fb76 -0, 29, 29, 1, 304128, 0x5efa175c -0, 30, 30, 1, 304128, 0x72c14f39 -0, 31, 31, 1, 304128, 0xd7c46bb0 -0, 32, 32, 1, 304128, 0x20f368ab -0, 33, 33, 1, 304128, 0x9bea7ced -0, 34, 34, 1, 304128, 0xf1b66b94 -0, 35, 35, 1, 304128, 0x3e5e6815 -0, 36, 36, 1, 304128, 0x6c2d5e3a -0, 37, 37, 1, 304128, 0x763046b0 -0, 38, 38, 1, 304128, 0x05f71f4c -0, 39, 39, 1, 304128, 0x3db72dff -0, 40, 40, 1, 304128, 0x86e34c11 -0, 41, 41, 1, 304128, 0x09334889 -0, 42, 42, 1, 304128, 0xc8566851 -0, 43, 43, 1, 304128, 0x4a7ec9da -0, 44, 44, 1, 304128, 0x609a176b -0, 45, 45, 1, 304128, 0x98deede0 -0, 46, 46, 1, 304128, 0x59ee66a3 -0, 47, 47, 1, 304128, 0x0fc5c8c2 -0, 48, 48, 1, 304128, 0x0371d7b0 -0, 49, 49, 1, 304128, 0xd81c18cf +0, 0, 0, 1, 304128, 0xf6aa0942 +0, 1, 1, 1, 304128, 0x5752d4ab +0, 2, 2, 1, 304128, 0x3052ede5 +0, 3, 3, 1, 304128, 0xdaf807b7 +0, 4, 4, 1, 304128, 0x8f5c9990 +0, 5, 5, 1, 304128, 0x75b58b80 +0, 6, 6, 1, 304128, 0x5b9c7b06 +0, 7, 7, 1, 304128, 0xee9c177a +0, 8, 8, 1, 304128, 0x4fefb449 +0, 9, 9, 1, 304128, 0x0a6d565d +0, 10, 10, 1, 304128, 0x25fe7635 +0, 11, 11, 1, 304128, 0x1d36be60 +0, 12, 12, 1, 304128, 0xa63f571a +0, 13, 13, 1, 304128, 0x7ec1f6b5 +0, 14, 14, 1, 304128, 0x8c240ccf +0, 15, 15, 1, 304128, 0x41bbbc2a +0, 16, 16, 1, 304128, 0x611319e8 +0, 17, 17, 1, 304128, 0x929d83ad +0, 18, 18, 1, 304128, 0x45ae42a0 +0, 19, 19, 1, 304128, 0x9dd20a04 +0, 20, 20, 1, 304128, 0x61230985 +0, 21, 21, 1, 304128, 0x643a6d0f +0, 22, 22, 1, 304128, 0x5dd530dd +0, 23, 23, 1, 304128, 0x92c56539 +0, 24, 24, 1, 304128, 0xc364f034 +0, 25, 25, 1, 304128, 0x7a476be9 +0, 26, 26, 1, 304128, 0xee4ac625 +0, 27, 27, 1, 304128, 0x9e9c13c4 +0, 28, 28, 1, 304128, 0x6097cda9 +0, 29, 29, 1, 304128, 0x3a6c370c +0, 30, 30, 1, 304128, 0xfa740b74 +0, 31, 31, 1, 304128, 0x9d13798e +0, 32, 32, 1, 304128, 0x61b5ffc1 +0, 33, 33, 1, 304128, 0x34b30667 +0, 34, 34, 1, 304128, 0x303681b4 +0, 35, 35, 1, 304128, 0xe63508fc +0, 36, 36, 1, 304128, 0x10ef6b65 +0, 37, 37, 1, 304128, 0x17c8d2b5 +0, 38, 38, 1, 304128, 0x053d9db5 +0, 39, 39, 1, 304128, 0x43dd5c5b +0, 40, 40, 1, 304128, 0xba4b65f2 +0, 41, 41, 1, 304128, 0x4dc70aa2 +0, 42, 42, 1, 304128, 0x9e2a528f +0, 43, 43, 1, 304128, 0x53df2931 +0, 44, 44, 1, 304128, 0xe1d12fbd +0, 45, 45, 1, 304128, 0xcb863c4c +0, 46, 46, 1, 304128, 0x528e2e81 +0, 47, 47, 1, 304128, 0x880c0b66 +0, 48, 48, 1, 304128, 0x83ec648a +0, 49, 49, 1, 304128, 0xa5d2555d diff --git a/tests/ref/fate/filter-setpts b/tests/ref/fate/filter-setpts index efdcf6a16e..08e0203831 100644 --- a/tests/ref/fate/filter-setpts +++ b/tests/ref/fate/filter-setpts @@ -1,42 +1,55 @@ -#tb 0: 1/25 +#tb 0: 1/1000 #media_type 0: video #codec_id 0: rawvideo #dimensions 0: 352x288 #sar 0: 0/1 -0, 0, 0, 1, 152064, 0x05b789ef -0, 1, 1, 1, 152064, 0x4bb46551 -0, 2, 2, 1, 152064, 0x9dddf64a -0, 3, 3, 1, 152064, 0x2a8380b0 -0, 4, 4, 1, 152064, 0x4de3b652 -0, 5, 5, 1, 152064, 0xedb5a8e6 -0, 6, 6, 1, 152064, 0x5ab58bac -0, 7, 7, 1, 152064, 0x1f1b8026 -0, 8, 8, 1, 152064, 0x91373915 -0, 9, 9, 1, 152064, 0x30f5fcd5 -0, 10, 10, 1, 152064, 0xc711ad61 -0, 11, 11, 1, 152064, 0x52a48ddd -0, 12, 12, 1, 152064, 0xa91c0f05 -0, 13, 13, 1, 152064, 0x8e364e18 -0, 14, 14, 1, 152064, 0xf25f6acc -0, 15, 15, 1, 152064, 0xf34ddbff -0, 16, 16, 1, 152064, 0x9dc72412 -0, 17, 17, 1, 152064, 0x445d1d59 -0, 18, 18, 1, 152064, 0x2f2768ef -0, 19, 19, 1, 152064, 0x95579936 -0, 20, 20, 1, 152064, 0x43d796b5 -0, 21, 21, 1, 152064, 0x76d2a455 -0, 22, 22, 1, 152064, 0x6dc3650e -0, 23, 23, 1, 152064, 0x0f9d6aca -0, 24, 24, 1, 152064, 0xd766fc8d -0, 25, 25, 1, 152064, 0xe22f7a30 -0, 26, 26, 1, 152064, 0xfa8d94fb -0, 27, 27, 1, 152064, 0x4c9737ab -0, 28, 28, 1, 152064, 0xa50d01f8 -0, 29, 29, 1, 152064, 0x88734edd -0, 30, 30, 1, 152064, 0xd2735925 -0, 31, 31, 1, 152064, 0x20cebfa9 -0, 32, 32, 1, 152064, 0x575c20ec -0, 33, 33, 1, 152064, 0x61b47e73 -0, 34, 34, 1, 152064, 0x09ef53ff -0, 35, 35, 1, 152064, 0x6e88c5c2 -0, 36, 36, 1, 152064, 0x4bbad8ea +0, 0, 0, 0, 152064, 0x05b789ef +0, 28, 28, 0, 152064, 0x4bb46551 +0, 57, 57, 0, 152064, 0x9dddf64a +0, 86, 86, 0, 152064, 0x2a8380b0 +0, 115, 115, 0, 152064, 0x4de3b652 +0, 144, 144, 0, 152064, 0xedb5a8e6 +0, 172, 172, 0, 152064, 0xe20f7c23 +0, 201, 201, 0, 152064, 0x5ab58bac +0, 229, 229, 0, 152064, 0x1f1b8026 +0, 258, 258, 0, 152064, 0x91373915 +0, 286, 286, 0, 152064, 0x02344760 +0, 314, 314, 0, 152064, 0x30f5fcd5 +0, 343, 343, 0, 152064, 0xc711ad61 +0, 371, 371, 0, 152064, 0x24eca223 +0, 399, 399, 0, 152064, 0x52a48ddd +0, 427, 427, 0, 152064, 0xa91c0f05 +0, 456, 456, 0, 152064, 0x8e364e18 +0, 484, 484, 0, 152064, 0xb15d38c8 +0, 512, 512, 0, 152064, 0xf25f6acc +0, 541, 541, 0, 152064, 0xf34ddbff +0, 570, 570, 0, 152064, 0xfc7bf570 +0, 598, 598, 0, 152064, 0x9dc72412 +0, 627, 627, 0, 152064, 0x445d1d59 +0, 656, 656, 0, 152064, 0x2f2768ef +0, 685, 685, 0, 152064, 0xce09f9d6 +0, 714, 714, 0, 152064, 0x95579936 +0, 743, 743, 0, 152064, 0x43d796b5 +0, 772, 772, 0, 152064, 0xd780d887 +0, 800, 800, 0, 152064, 0x76d2a455 +0, 829, 829, 0, 152064, 0x6dc3650e +0, 858, 858, 0, 152064, 0x0f9d6aca +0, 887, 887, 0, 152064, 0xe295c51e +0, 915, 915, 0, 152064, 0xd766fc8d +0, 944, 944, 0, 152064, 0xe22f7a30 +0, 972, 972, 0, 152064, 0x7fea4378 +0, 1000, 1000, 0, 152064, 0xfa8d94fb +0, 1029, 1029, 0, 152064, 0x4c9737ab +0, 1057, 1057, 0, 152064, 0xa50d01f8 +0, 1085, 1085, 0, 152064, 0x0b07594c +0, 1113, 1113, 0, 152064, 0x88734edd +0, 1142, 1142, 0, 152064, 0xd2735925 +0, 1170, 1170, 0, 152064, 0xd4e49e08 +0, 1198, 1198, 0, 152064, 0x20cebfa9 +0, 1227, 1227, 0, 152064, 0x575c20ec +0, 1255, 1255, 0, 152064, 0xfd500471 +0, 1284, 1284, 0, 152064, 0x61b47e73 +0, 1313, 1313, 0, 152064, 0x09ef53ff +0, 1341, 1341, 0, 152064, 0x6e88c5c2 +0, 1370, 1370, 0, 152064, 0xbb87b483 +0, 1399, 1399, 0, 152064, 0x4bbad8ea diff --git a/tests/ref/fate/force_key_frames b/tests/ref/fate/force_key_frames index 26de0905e8..ef8ca5af32 100644 --- a/tests/ref/fate/force_key_frames +++ b/tests/ref/fate/force_key_frames @@ -1,4 +1,4 @@ -07567b9528b8de523faaf49e4e1e0fc6 *tests/data/fate/force_key_frames.avi -113312 tests/data/fate/force_key_frames.avi -b2e92b97bac0243242281d71108ffdbd *tests/data/fate/force_key_frames.out.framecrc -stddev:34612.83 PSNR: 5.54 MAXDIFF:61408 bytes: 7603200/ 264 +1cd5f12691d602ef806606b0dc22fddc *tests/data/fate/force_key_frames.avi +574816 tests/data/fate/force_key_frames.avi +7c41fec64a8d44148f4fb81d31c5027c *tests/data/fate/force_key_frames.out.framecrc +stddev:29597.16 PSNR: 6.90 MAXDIFF:60652 bytes: 7603200/ 264 diff --git a/tests/ref/fate/libx265-hdr10 b/tests/ref/fate/libx265-hdr10 deleted file mode 100644 index 571c837cac..0000000000 --- a/tests/ref/fate/libx265-hdr10 +++ /dev/null @@ -1,16 +0,0 @@ -frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data Unregistered SEI message" -frames.frame.0.side_data_list.side_data.1.side_data_type="H.26[45] User Data Unregistered SEI message" -frames.frame.0.side_data_list.side_data.2.side_data_type="Mastering display metadata" -frames.frame.0.side_data_list.side_data.2.red_x="13250/50000" -frames.frame.0.side_data_list.side_data.2.red_y="34500/50000" -frames.frame.0.side_data_list.side_data.2.green_x="7500/50000" -frames.frame.0.side_data_list.side_data.2.green_y="3000/50000" -frames.frame.0.side_data_list.side_data.2.blue_x="34000/50000" -frames.frame.0.side_data_list.side_data.2.blue_y="16000/50000" -frames.frame.0.side_data_list.side_data.2.white_point_x="15635/50000" -frames.frame.0.side_data_list.side_data.2.white_point_y="16450/50000" -frames.frame.0.side_data_list.side_data.2.min_luminance="50/10000" -frames.frame.0.side_data_list.side_data.2.max_luminance="10000000/10000" -frames.frame.0.side_data_list.side_data.3.side_data_type="Content light level metadata" -frames.frame.0.side_data_list.side_data.3.max_content=1000 -frames.frame.0.side_data_list.side_data.3.max_average=200 diff --git a/tests/ref/fate/mov-mp4-iamf-5_1_4 b/tests/ref/fate/mov-mp4-iamf-5_1_4 index 36a94143b5..a6d5a76b0d 100644 --- a/tests/ref/fate/mov-mp4-iamf-5_1_4 +++ b/tests/ref/fate/mov-mp4-iamf-5_1_4 @@ -1,4 +1,4 @@ -5585ed23481b6f28437b3707a1ed632d *tests/data/fate/mov-mp4-iamf-5_1_4.mp4 +0316d0a483480ccd582fd20f06c77420 *tests/data/fate/mov-mp4-iamf-5_1_4.mp4 86340 tests/data/fate/mov-mp4-iamf-5_1_4.mp4 #extradata 0: 34, 0xafa70d5e #extradata 1: 34, 0xafa70d5e diff --git a/tests/ref/fate/mov-mp4-iamf-7_1_4 b/tests/ref/fate/mov-mp4-iamf-7_1_4 index d5014387b6..0641cb0c3c 100644 --- a/tests/ref/fate/mov-mp4-iamf-7_1_4 +++ b/tests/ref/fate/mov-mp4-iamf-7_1_4 @@ -1,4 +1,4 @@ -690d2b7a15b5489c59a9148fcd7975be *tests/data/fate/mov-mp4-iamf-7_1_4.mp4 +d9ef5d14bbd37c5a06c1494cacdb8f29 *tests/data/fate/mov-mp4-iamf-7_1_4.mp4 100588 tests/data/fate/mov-mp4-iamf-7_1_4.mp4 #extradata 0: 34, 0xafa70d5e #extradata 1: 34, 0xafa70d5e diff --git a/tests/ref/fate/mov-mp4-iamf-ambisonic_1 b/tests/ref/fate/mov-mp4-iamf-ambisonic_1 index 088fc9a028..a5b3581124 100644 --- a/tests/ref/fate/mov-mp4-iamf-ambisonic_1 +++ b/tests/ref/fate/mov-mp4-iamf-ambisonic_1 @@ -1,4 +1,4 @@ -2b3517591f7bf20e0f74f3ec1381af1e *tests/data/fate/mov-mp4-iamf-ambisonic_1.mp4 +b0f4accdb8f1f3dfe594a6cbd6c00603 *tests/data/fate/mov-mp4-iamf-ambisonic_1.mp4 57743 tests/data/fate/mov-mp4-iamf-ambisonic_1.mp4 #extradata 0: 34, 0xad120cfe #extradata 1: 34, 0xad120cfe diff --git a/tests/ref/fate/mov-mp4-iamf-stereo b/tests/ref/fate/mov-mp4-iamf-stereo index bf141c6755..6526a7bcf4 100644 --- a/tests/ref/fate/mov-mp4-iamf-stereo +++ b/tests/ref/fate/mov-mp4-iamf-stereo @@ -1,4 +1,4 @@ -88c2b547f069f2d4a11d24f7f922251a *tests/data/fate/mov-mp4-iamf-stereo.mp4 +87c17d1a9fd07e16c369d386d39c3249 *tests/data/fate/mov-mp4-iamf-stereo.mp4 15163 tests/data/fate/mov-mp4-iamf-stereo.mp4 #extradata 0: 34, 0xafa70d5e #tb 0: 1/44100 diff --git a/tests/ref/fate/shortest b/tests/ref/fate/shortest index b5845508cf..0690799d8d 100644 --- a/tests/ref/fate/shortest +++ b/tests/ref/fate/shortest @@ -9,109 +9,109 @@ #sample_rate 1: 44100 #channel_layout_name 1: mono 1, -256, -256, 1536, 416, 0x69efcbcc -0, 0, 0, 1, 8749, 0x57039d10, S=1, 8 +0, 0, 0, 1, 27867, 0x1426a0d6, S=1, 8 1, 1280, 1280, 1536, 418, 0xa0ccc09d -0, 1, 1, 1, 975, 0x2fcf0617, F=0x0, S=1, 8 +0, 1, 1, 1, 9806, 0xbebc2826, F=0x0, S=1, 8 1, 2816, 2816, 1536, 418, 0xb873cb60 -0, 2, 2, 1, 1167, 0x6d32482b, F=0x0, S=1, 8 +0, 2, 2, 1, 10453, 0x4a188450, F=0x0, S=1, 8 1, 4352, 4352, 1536, 418, 0x1366c008 -0, 3, 3, 1, 1274, 0xab1d80c9, F=0x0, S=1, 8 +0, 3, 3, 1, 10248, 0x4c831c08, F=0x0, S=1, 8 1, 5888, 5888, 1536, 418, 0xeb24c8da -0, 4, 4, 1, 1361, 0x9dc28a69, F=0x0, S=1, 8 +0, 4, 4, 1, 11680, 0x5508c44d, F=0x0, S=1, 8 1, 7424, 7424, 1536, 418, 0xc75ac55e -0, 5, 5, 1, 1415, 0x41d8ba3e, F=0x0, S=1, 8 +0, 5, 5, 1, 11046, 0x096ca433, F=0x0, S=1, 8 1, 8960, 8960, 1536, 418, 0xe336d28d 1, 10496, 10496, 1536, 418, 0xd0acc452 -0, 6, 6, 1, 1421, 0x8c83ad35, F=0x0, S=1, 8 +0, 6, 6, 1, 9888, 0x440a5b45, F=0x0, S=1, 8 1, 12032, 12032, 1536, 418, 0xae88c75f -0, 7, 7, 1, 1474, 0x1025b9b0, F=0x0, S=1, 8 +0, 7, 7, 1, 10165, 0x116d4909, F=0x0, S=1, 8 1, 13568, 13568, 1536, 418, 0xa200b8f0 -0, 8, 8, 1, 1467, 0xf3c0c714, F=0x0, S=1, 8 +0, 8, 8, 1, 11704, 0xb334a24c, F=0x0, S=1, 8 1, 15104, 15104, 1536, 418, 0x009dccf6 -0, 9, 9, 1, 1469, 0x1b9faf72, F=0x0, S=1, 8 +0, 9, 9, 1, 11059, 0x49aa6515, F=0x0, S=1, 8 1, 16640, 16640, 1536, 418, 0x585ec129 -0, 10, 10, 1, 1506, 0x18a9c359, F=0x0, S=1, 8 +0, 10, 10, 1, 8764, 0x8214fab0, F=0x0, S=1, 8 1, 18176, 18176, 1536, 418, 0xda1acf75 -0, 11, 11, 1, 1520, 0x0ec1d39a, F=0x0, S=1, 8 +0, 11, 11, 1, 9328, 0x92987740, F=0x0, S=1, 8 1, 19712, 19712, 1536, 418, 0xd326d279 -0, 12, 12, 1, 8554, 0xfab776e0, S=1, 8 +0, 12, 12, 1, 27955, 0xe25edb6c, S=1, 8 1, 21248, 21248, 1536, 418, 0x1b54bf76 1, 22784, 22784, 1536, 418, 0xdb39cbd1 -0, 13, 13, 1, 1079, 0x13e40cb3, F=0x0, S=1, 8 +0, 13, 13, 1, 11181, 0x3cf56687, F=0x0, S=1, 8 1, 24320, 24320, 1536, 418, 0x6813cefa -0, 14, 14, 1, 1343, 0xf0058d2e, F=0x0, S=1, 8 +0, 14, 14, 1, 12002, 0x87942530, F=0x0, S=1, 8 1, 25856, 25856, 1536, 418, 0xb402d2ec -0, 15, 15, 1, 1486, 0x1da1c64e, F=0x0, S=1, 8 +0, 15, 15, 1, 10122, 0xbb10e8d9, F=0x0, S=1, 8 1, 27392, 27392, 1536, 418, 0x80c4c8d2 -0, 16, 16, 1, 1491, 0x872dd43d, F=0x0, S=1, 8 +0, 16, 16, 1, 9715, 0xa4a1325c, F=0x0, S=1, 8 1, 28928, 28928, 1536, 418, 0xaeaac123 -0, 17, 17, 1, 1504, 0x5907c6ca, F=0x0, S=1, 8 +0, 17, 17, 1, 11222, 0x15118a48, F=0x0, S=1, 8 1, 30464, 30464, 1536, 418, 0xe2c9c038 -0, 18, 18, 1, 1481, 0xde66ba0a, F=0x0, S=1, 8 +0, 18, 18, 1, 11384, 0xd4304391, F=0x0, S=1, 8 1, 32000, 32000, 1536, 418, 0x3f37c65b -0, 19, 19, 1, 1521, 0xf46dcef9, F=0x0, S=1, 8 +0, 19, 19, 1, 9141, 0xabd1eb90, F=0x0, S=1, 8 1, 33536, 33536, 1536, 418, 0xf9a2cf98 1, 35072, 35072, 1536, 418, 0xc951cbb5 -0, 20, 20, 1, 1514, 0x001ed7b1, F=0x0, S=1, 8 +0, 20, 20, 1, 10049, 0x5b388bc2, F=0x0, S=1, 8 1, 36608, 36608, 1536, 418, 0x4e92be94 -0, 21, 21, 1, 1562, 0x3974e095, F=0x0, S=1, 8 +0, 21, 21, 1, 9049, 0x214505c3, F=0x0, S=1, 8 1, 38144, 38144, 1536, 418, 0xa9d8c8d0 -0, 22, 22, 1, 1562, 0xa94bf1fc, F=0x0, S=1, 8 +0, 22, 22, 1, 9101, 0xdba6e5ba, F=0x0, S=1, 8 1, 39680, 39680, 1536, 418, 0xe4c8bc20 -0, 23, 23, 1, 1629, 0xdfcc0234, F=0x0, S=1, 8 +0, 23, 23, 1, 10351, 0x0aea5644, F=0x0, S=1, 8 1, 41216, 41216, 1536, 418, 0x2ccac571 -0, 24, 24, 1, 9664, 0xbf319bb0, S=1, 8 +0, 24, 24, 1, 27864, 0xd0287877, S=1, 8 1, 42752, 42752, 1536, 418, 0xd2a0cbff -0, 25, 25, 1, 1239, 0x1f9662f7, F=0x0, S=1, 8 +0, 25, 25, 1, 9026, 0x01ec7d47, F=0x0, S=1, 8 1, 44288, 44288, 1536, 418, 0xffadb489 1, 45824, 45824, 1536, 418, 0x1246cae7 -0, 26, 26, 1, 1568, 0xfbf8ed9d, F=0x0, S=1, 8 +0, 26, 26, 1, 8894, 0x5917d83b, F=0x0, S=1, 8 1, 47360, 47360, 1536, 418, 0xa74eb1f7 -0, 27, 27, 1, 1641, 0x46aafde5, F=0x0, S=1, 8 +0, 27, 27, 1, 10119, 0x3a2ede3a, F=0x0, S=1, 8 1, 48896, 48896, 1536, 418, 0x98cfc032 -0, 28, 28, 1, 1735, 0xa9363e9b, F=0x0, S=1, 8 +0, 28, 28, 1, 10290, 0xea641449, F=0x0, S=1, 8 1, 50432, 50432, 1536, 418, 0x8045c0a7 -0, 29, 29, 1, 1760, 0x99b82cbc, F=0x0, S=1, 8 +0, 29, 29, 1, 10922, 0xeb7e9700, F=0x0, S=1, 8 1, 51968, 51968, 1536, 418, 0x2180c196 -0, 30, 30, 1, 1798, 0xc0ba5286, F=0x0, S=1, 8 +0, 30, 30, 1, 9680, 0x929d1f59, F=0x0, S=1, 8 1, 53504, 53504, 1536, 418, 0x35f2b4d1 -0, 31, 31, 1, 1830, 0x4e8b4b80, F=0x0, S=1, 8 +0, 31, 31, 1, 8733, 0x8fa8fc4e, F=0x0, S=1, 8 1, 55040, 55040, 1536, 418, 0x876ec74d -0, 32, 32, 1, 1835, 0x218a69cb, F=0x0, S=1, 8 +0, 32, 32, 1, 9878, 0xe3f555e9, F=0x0, S=1, 8 1, 56576, 56576, 1536, 418, 0xbccebddd 1, 58112, 58112, 1536, 418, 0x40a1bcc7 -0, 33, 33, 1, 1902, 0x8f2b67d2, F=0x0, S=1, 8 +0, 33, 33, 1, 10926, 0x2a2bed74, F=0x0, S=1, 8 1, 59648, 59648, 1536, 418, 0xbd10bf09 -0, 34, 34, 1, 1886, 0xf4087481, F=0x0, S=1, 8 +0, 34, 34, 1, 12170, 0x70c8ab23, F=0x0, S=1, 8 1, 61184, 61184, 1536, 418, 0xb8e4b630 -0, 35, 35, 1, 1949, 0x142c8ac1, F=0x0, S=1, 8 +0, 35, 35, 1, 11631, 0x7d5e8297, F=0x0, S=1, 8 1, 62720, 62720, 1536, 418, 0xc667bd39 -0, 36, 36, 1, 10806, 0x603680c3, S=1, 8 +0, 36, 36, 1, 28056, 0x10bef294, S=1, 8 1, 64256, 64256, 1536, 418, 0x2985c4ac -0, 37, 37, 1, 1413, 0xc52395a2, F=0x0, S=1, 8 +0, 37, 37, 1, 11067, 0x490af43b, F=0x0, S=1, 8 1, 65792, 65792, 1536, 418, 0xb229b697 -0, 38, 38, 1, 1731, 0xa26a2fb2, F=0x0, S=1, 8 +0, 38, 38, 1, 11046, 0x6dba2441, F=0x0, S=1, 8 1, 67328, 67328, 1536, 418, 0xd2eec6d8 -0, 39, 39, 1, 1888, 0xa2995d2a, F=0x0, S=1, 8 +0, 39, 39, 1, 10922, 0x069cfa74, F=0x0, S=1, 8 1, 68864, 68864, 1536, 418, 0x74a9c1a9 1, 70400, 70400, 1536, 418, 0x2d1cc383 -0, 40, 40, 1, 1989, 0x0274904a, F=0x0, S=1, 8 +0, 40, 40, 1, 11477, 0x18baebc1, F=0x0, S=1, 8 1, 71936, 71936, 1536, 418, 0x0ad9c88a -0, 41, 41, 1, 1949, 0x66fa8de9, F=0x0, S=1, 8 +0, 41, 41, 1, 10285, 0x792623a6, F=0x0, S=1, 8 1, 73472, 73472, 1536, 418, 0x9aa3d0a7 -0, 42, 42, 1, 1956, 0x4e2e831d, F=0x0, S=1, 8 +0, 42, 42, 1, 9961, 0x69d8a3b1, F=0x0, S=1, 8 1, 75008, 75008, 1536, 416, 0x99f5b2b6 -0, 43, 43, 1, 2012, 0x1d75ac7a, F=0x0, S=1, 8 +0, 43, 43, 1, 11162, 0x6f3788c6, F=0x0, S=1, 8 1, 76544, 76544, 1536, 418, 0xfb7dc20d -0, 44, 44, 1, 1995, 0xdc478fec, F=0x0, S=1, 8 +0, 44, 44, 1, 10696, 0x524ad4f8, F=0x0, S=1, 8 1, 78080, 78080, 1536, 418, 0xebc8c568 -0, 45, 45, 1, 2078, 0x416aaf11, F=0x0, S=1, 8 +0, 45, 45, 1, 10319, 0x9d6ff8f7, F=0x0, S=1, 8 1, 79616, 79616, 1536, 418, 0x7361c949 -0, 46, 46, 1, 2116, 0x1416cc81, F=0x0, S=1, 8 +0, 46, 46, 1, 8796, 0xb0cc869e, F=0x0, S=1, 8 1, 81152, 81152, 1536, 418, 0x85d8bbd0 1, 82688, 82688, 1536, 418, 0x72e8bad1 -0, 47, 47, 1, 2024, 0xf1c1ad7d, F=0x0, S=1, 8 +0, 47, 47, 1, 8779, 0x2027399c, F=0x0, S=1, 8 1, 84224, 84224, 1536, 418, 0x4febb56f -0, 48, 48, 1, 11212, 0xc61a3f0a, S=1, 8 +0, 48, 48, 1, 28143, 0x1df268c5, S=1, 8 1, 85760, 85760, 1536, 418, 0xae06ca91 -0, 49, 49, 1, 1423, 0x45fba9e4, F=0x0, S=1, 8 +0, 49, 49, 1, 10073, 0xedb9f031, F=0x0, S=1, 8 diff --git a/tests/ref/fate/source b/tests/ref/fate/source index 7b5f14b4f0..d8d4224145 100644 --- a/tests/ref/fate/source +++ b/tests/ref/fate/source @@ -10,6 +10,7 @@ libavdevice/reverse.c libavfilter/af_arnndn.c libavfilter/file_open.c libavfilter/log2_tab.c +libavformat/bitstream.c libavformat/file_open.c libavformat/golomb_tab.c libavformat/log2_tab.c diff --git a/tests/ref/fate/vvc-conformance-OPI_B_3 b/tests/ref/fate/vvc-conformance-OPI_B_3 deleted file mode 100644 index 6ce3b46a21..0000000000 --- a/tests/ref/fate/vvc-conformance-OPI_B_3 +++ /dev/null @@ -1,6 +0,0 @@ -#tb 0: 1/25 -#media_type 0: video -#codec_id 0: rawvideo -#dimensions 0: 416x240 -#sar 0: 0/1 -0, 0, 0, 1, 299520, 0xdf1640db diff --git a/tests/ref/fate/vvc-conformance-VPS_A_3 b/tests/ref/fate/vvc-conformance-VPS_A_3 deleted file mode 100644 index bf9326b051..0000000000 --- a/tests/ref/fate/vvc-conformance-VPS_A_3 +++ /dev/null @@ -1,6 +0,0 @@ -#tb 0: 1/25 -#media_type 0: video -#codec_id 0: rawvideo -#dimensions 0: 208x120 -#sar 0: 0/1 -0, 0, 0, 1, 74880, 0x1b401a6d diff --git a/tools/coverity.c b/tools/coverity.c index 19a132a976..541e108238 100644 --- a/tools/coverity.c +++ b/tools/coverity.c @@ -31,6 +31,17 @@ #define NULL (void *)0 +typedef long long int64_t; + +enum AVRounding { + AV_ROUND_ZERO = 0, + AV_ROUND_INF = 1, + AV_ROUND_DOWN = 2, + AV_ROUND_UP = 3, + AV_ROUND_NEAR_INF = 5, + AV_ROUND_PASS_MINMAX = 8192, +}; + // Based on https://scan.coverity.com/models void *av_malloc(size_t size) { int has_memory; @@ -77,3 +88,10 @@ void *av_free(void *ptr) { __coverity_mark_as_afm_freed__(ptr, "av_free"); } + +int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd) { + __coverity_negative_sink__(b); + __coverity_negative_sink__(c); + + return (double)a * (double)b / (double)c; +} diff --git a/tools/decode_simple.c b/tools/decode_simple.c index 6532e368d4..e8c1d6a407 100644 --- a/tools/decode_simple.c +++ b/tools/decode_simple.c @@ -94,8 +94,9 @@ int ds_run(DecodeContext *dc) goto finish; } - avcodec_send_packet(dc->decoder, NULL); - ret = decode_read(dc, 1); + ret = avcodec_send_packet(dc->decoder, NULL); + if (ret >= 0) + ret = decode_read(dc, 1); if (ret < 0) { fprintf(stderr, "Error flushing: %d\n", ret); return ret; diff --git a/tools/enc_recon_frame_test.c b/tools/enc_recon_frame_test.c index a8e152bf44..798fb772e8 100644 --- a/tools/enc_recon_frame_test.c +++ b/tools/enc_recon_frame_test.c @@ -28,6 +28,7 @@ #include "decode_simple.h" #include "libavutil/adler32.h" +#include "libavutil/avassert.h" #include "libavutil/common.h" #include "libavutil/error.h" #include "libavutil/frame.h" @@ -88,6 +89,8 @@ static int frame_hash(FrameChecksum **pc, size_t *nb_c, int64_t ts, int linesize = av_image_get_linesize(frame->format, frame->width, p); uint32_t checksum = 0; + av_assert0(linesize >= 0); + for (int j = 0; j < frame->height >> shift_v[p]; j++) { checksum = av_adler32_update(checksum, data, linesize); data += frame->linesize[p]; diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c index 8d19988999..8d817eea33 100644 --- a/tools/target_dec_fuzzer.c +++ b/tools/target_dec_fuzzer.c @@ -128,7 +128,14 @@ static int fuzz_video_get_buffer(AVCodecContext *ctx, AVFrame *frame) frame->extended_data = frame->data; for (i = 0; i < 4 && size[i]; i++) { - frame->buf[i] = av_buffer_alloc(size[i]); + switch(ctx->codec_id) { + case AV_CODEC_ID_FFV1: + frame->buf[i] = av_buffer_alloc(size[i]); + break; + default: + frame->buf[i] = av_buffer_allocz(size[i]); + } + if (!frame->buf[i]) goto fail; frame->data[i] = frame->buf[i]->data; @@ -229,6 +236,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { case AV_CODEC_ID_DVB_SUBTITLE: av_dict_set_int(&opts, "compute_clut", -2, 0); break; case AV_CODEC_ID_DXA: maxpixels /= 32; break; case AV_CODEC_ID_DXV: maxpixels /= 32; break; + case AV_CODEC_ID_CMV: maxpixels /= 256; break; case AV_CODEC_ID_EXR: maxpixels /= 1024; break; case AV_CODEC_ID_FFV1: maxpixels /= 32; break; case AV_CODEC_ID_FFWAVESYNTH: maxsamples /= 16384; break; @@ -247,8 +255,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { case AV_CODEC_ID_HQ_HQA: maxpixels /= 128; break; case AV_CODEC_ID_IFF_ILBM: maxpixels /= 4096; break; case AV_CODEC_ID_INDEO4: maxpixels /= 128; break; + case AV_CODEC_ID_INDEO5: maxpixels /= 1024; break; case AV_CODEC_ID_INTERPLAY_ACM: maxsamples /= 16384; break; - case AV_CODEC_ID_JPEG2000: maxpixels /= 4096; break; + case AV_CODEC_ID_JPEG2000: maxpixels /= 16384; break; case AV_CODEC_ID_LAGARITH: maxpixels /= 1024; break; case AV_CODEC_ID_LOCO: maxpixels /= 1024; break; case AV_CODEC_ID_VORBIS: maxsamples /= 1024; break; @@ -261,6 +270,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { case AV_CODEC_ID_MSS2: maxpixels /= 16384; break; case AV_CODEC_ID_MSZH: maxpixels /= 128; break; case AV_CODEC_ID_MTS2: maxpixels /= 4096; break; + case AV_CODEC_ID_MV30: maxpixels /= 128; break; + case AV_CODEC_ID_MVC1: maxpixels /= 1024; break; case AV_CODEC_ID_MVC2: maxpixels /= 128; break; case AV_CODEC_ID_MVHA: maxpixels /= 16384; break; case AV_CODEC_ID_MVDV: maxpixels /= 1024; break; @@ -276,7 +287,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { case AV_CODEC_ID_QPEG: maxpixels /= 256; break; case AV_CODEC_ID_RKA: maxsamples /= 1<<20; break; case AV_CODEC_ID_RSCC: maxpixels /= 256; break; - case AV_CODEC_ID_RASC: maxpixels /= 16; break; + case AV_CODEC_ID_RASC: maxpixels /= 256; break; case AV_CODEC_ID_RTV1: maxpixels /= 16; break; case AV_CODEC_ID_SANM: maxpixels /= 16; break; case AV_CODEC_ID_SCPR: maxpixels /= 32; break;