Opened 3 years ago

Closed 3 years ago

#9196 closed defect (fixed)

adelay suffers integer overflow when delaying over 2^31-1 samples

Reported by: frumsdotxyz Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: adelay
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by frumsdotxyz)

I'm not sure how widely-scoped this issue is, but adelay seems to be managing sample counts for delays in unsigned 32-bit integers, and complains about negative input values when those counts would overflow - for instance, using a 50_000_000 millisecond delay on a video with a 48 kHZ audio track, or (as in the sample below) a 100_000_000 millisecond delay on a 22.05 kHz audio file.
Output for a sample transformation, and output for an ex input file itself are provided, but this problem was reproduced across several platforms/input audio files/versions, including 4.4.0-r0 (Alpine distribution).

This was first discovered when processing and time-aligning the audio tracks of long video recordings with multiple slices made over the course of a day, which is where the original ~50k second figure (around 14 hours) was discovered.

ffmpeg started on 2021-04-19 at 14:00:35
Report written to "ffmpeg-20210419-140035.log"
Log level: 48
Command line:
ffmpeg -i zombo.mp3 -af "adelay=delays=100000000:all=1" -report out.mp3
ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.29)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Splitting the commandline.
Reading option '-i' ... matched as input url with argument 'zombo.mp3'.
Reading option '-af' ... matched as option 'af' (set audio filters) with argument 'adelay=delays=100000000:all=1'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option 'out.mp3' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url zombo.mp3.
Successfully parsed a group of options.
Opening an input file: zombo.mp3.
[NULL @ 0x7fe3f700e800] Opening 'zombo.mp3' for reading
[file @ 0x7fe3f4420e00] Setting default whitelist 'file,crypto,data'
[mp3 @ 0x7fe3f700e800] Format mp3 probed with size=2048 and score=51
[mp3 @ 0x7fe3f700e800] Skipping 0 bytes of junk at 0.
[mp3 @ 0x7fe3f700e800] Before avformat_find_stream_info() pos: 0 bytes read:65664 seeks:2 nb_streams:1
[mp3 @ 0x7fe3f700e800] All info found
[mp3 @ 0x7fe3f700e800] Estimating duration from bitrate, this may be inaccurate
[mp3 @ 0x7fe3f700e800] After avformat_find_stream_info() pos: 4096 bytes read:65664 seeks:2 frames:50
Input #0, mp3, from 'zombo.mp3':
  Duration: 00:01:45.48, start: 0.000000, bitrate: 24 kb/s
  Stream #0:0, 50, 1/14112000: Audio: mp3, 22050 Hz, mono, fltp, 24 kb/s
Successfully opened the file.
Parsing a group of options: output url out.mp3.
Applying option af (set audio filters) with argument adelay=delays=100000000:all=1.
Successfully parsed a group of options.
Opening an output file: out.mp3.
[file @ 0x7fe3f4707b00] Setting default whitelist 'file,crypto,data'
Successfully opened the file.
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (mp3float) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
detected 8 logical cores
[Parsed_adelay_0 @ 0x7fe3f5a04e80] Setting 'delays' to value '100000000'
[Parsed_adelay_0 @ 0x7fe3f5a04e80] Setting 'all' to value '1'
[graph_0_in_0_0 @ 0x7fe3f4424740] Setting 'time_base' to value '1/22050'
[graph_0_in_0_0 @ 0x7fe3f4424740] Setting 'sample_rate' to value '22050'
[graph_0_in_0_0 @ 0x7fe3f4424740] Setting 'sample_fmt' to value 'fltp'
[graph_0_in_0_0 @ 0x7fe3f4424740] Setting 'channel_layout' to value '0x4'
[graph_0_in_0_0 @ 0x7fe3f4424740] tb:1/22050 samplefmt:fltp samplerate:22050 chlayout:0x4
[format_out_0_0 @ 0x7fe3f4424bc0] Setting 'sample_fmts' to value 's32p|fltp|s16p'
[format_out_0_0 @ 0x7fe3f4424bc0] Setting 'sample_rates' to value '44100|48000|32000|22050|24000|16000|11025|12000|8000'
[format_out_0_0 @ 0x7fe3f4424bc0] Setting 'channel_layouts' to value '0x4|0x3'
[AVFilterGraph @ 0x7fe3f44245c0] query_formats: 4 queried, 9 merged, 0 already done, 0 delayed
[Parsed_adelay_0 @ 0x7fe3f5a04e80] Delay must be non negative number.
[Parsed_adelay_0 @ 0x7fe3f5a04e80] Failed to configure input pad on Parsed_adelay_0
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
[AVIOContext @ 0x7fe3f4422c00] Statistics: 0 seeks, 0 writeouts
[AVIOContext @ 0x7fe3f4420f80] Statistics: 65664 bytes read, 2 seeks
Conversion failed!
ffmpeg started on 2021-04-19 at 14:00:50
Report written to "ffmpeg-20210419-140050.log"
Log level: 99
Command line:
ffmpeg -v 9 -loglevel 99 -i zombo.mp3 -report
ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.29)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-i' ... matched as input url with argument 'zombo.mp3'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Applying option loglevel (set logging level) with argument 99.
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url zombo.mp3.
Successfully parsed a group of options.
Opening an input file: zombo.mp3.
[NULL @ 0x7fda90008200] Opening 'zombo.mp3' for reading
[file @ 0x7fda8d707800] Setting default whitelist 'file,crypto,data'
Probing mp3 score:51 size:2048
[mp3 @ 0x7fda90008200] Format mp3 probed with size=2048 and score=51
[mp3 @ 0x7fda90008200] Skipping 0 bytes of junk at 0.
[mp3 @ 0x7fda90008200] Before avformat_find_stream_info() pos: 0 bytes read:65664 seeks:2 nb_streams:1
[mp3 @ 0x7fda90008200] All info found
[mp3 @ 0x7fda90008200] Estimating duration from bitrate, this may be inaccurate
[mp3 @ 0x7fda90008200] stream 0: start_time: 0 duration: 105.482
[mp3 @ 0x7fda90008200] format: start_time: 0 duration: 105.482 (estimate from bit rate) bitrate=24 kb/s
[mp3 @ 0x7fda90008200] After avformat_find_stream_info() pos: 4096 bytes read:65664 seeks:2 frames:50
Input #0, mp3, from 'zombo.mp3':
  Duration: 00:01:45.48, start: 0.000000, bitrate: 24 kb/s
  Stream #0:0, 50, 1/14112000: Audio: mp3, 22050 Hz, mono, fltp, 24 kb/s
Successfully opened the file.
At least one output file must be specified
[AVIOContext @ 0x7fda8eb040c0] Statistics: 65664 bytes read, 2 seeks

Attachments (1)

zombo.mp3 (309.0 KB ) - added by frumsdotxyz 3 years ago.
Sample audio file for reproduction

Download all attachments as: .zip

Change History (5)

comment:1 by frumsdotxyz, 3 years ago

Description: modified (diff)

by frumsdotxyz, 3 years ago

Attachment: zombo.mp3 added

Sample audio file for reproduction

comment:2 by frumsdotxyz, 3 years ago

Summary: adelay suffers integer overflow when delaying over 2^32-1 samplesadelay suffers integer overflow when delaying over 2^31-1 samples

comment:3 by Gyan, 3 years ago

You can work around by using a combination of asetpts and aresample filters.

asetpts=PTS+50000/TB,aresample=async=1:first_pts=0

comment:4 by James, 3 years ago

Component: undeterminedavfilter
Keywords: avfilter removed
Resolution: fixed
Status: newclosed
Version: unspecifiedgit-master
Note: See TracTickets for help on using tickets.