1
0
mirror of https://git.ffmpeg.org/ffmpeg.git synced 2026-10-24 02:09:03 +03:00
Commit Graph

27261 Commits

Author SHA1 Message Date
Damiano Galassi
e25fefc85e avformat/movenc: fix mov_create_dvd_sub_decoder_specific_info
It has been broken since 3064487.

(cherry picked from commit 1aefacfda4)
Signed-off-by: Marvin Scholz <epirat07@gmail.com>
2026-10-21 19:32:37 +00:00
James Almer
46d899d7a0 avformat/mov: check ff_mov_read_chnl return value
Fixes use of uninitialized value.
Fixes issue #24960.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-10-11 11:11:53 -03:00
Timo Rothenpieler
c389840894 avformat/imfdec: don't busy-loop if non-Asset in Asset-list
(cherry picked from commit ef305e32e8)
2026-10-09 23:25:18 +00:00
Timo Rothenpieler
eb4d7e3c30 avformat/mux: don't let positive write_trailer ret shadow pb failure
(cherry picked from commit 1de217ad4b)
2026-09-29 19:26:10 +00:00
Sergei Iashin
6c5a6f053c libavformat/dashenc.c: check if packets were muxed before calculating average bitrate
Prevents SIGFPE.
Fixes issue #24738.

Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit d62aef2e50)
2026-09-27 11:51:00 -03:00
Timo Rothenpieler
45e8e0a3ff avformat/mov: don't leak on realloc failure
Fixes: #YWH-PGM40646-48
(cherry picked from commit d975849594)
2026-09-26 16:05:05 +00:00
Timo Rothenpieler
1041abdc96 avformat/tls_gnutls: actually send client cert if one is provided
Without setting this flag, apparently gnutls will only send the client
certificate according some logic based on what it thinks the server
accepts.
This is not the case a lot of times.
Just force it to send the client cert the user supplied, if one was
supplied, no matter what.

Fixes #22707

(cherry picked from commit 5c35d0b880)
2026-09-20 23:13:50 +00:00
Michael Niedermayer
a4a6cb1e4a Bump for 8.1.3 2026-09-19 18:28:12 +02:00
Jack Lau
6442b04b0f avformat/hlsenc: fix compile error when mp4 is disabled
Regression since dc4c798970

Handle the case where mp4 is disabled since mp4 as
an optional dependency of hls_muxer.

Signed-off-by: Jack Lau <jacklau1222gm@gmail.com>
(cherry picked from commit 0510aff11b)
2026-09-19 17:00:37 +02:00
Kacper Michajłow
51715a5344 avformat/hls: avoid casting callback functions type
Technically it's is UB to call function of different type.

Fixes:
src/libavformat/utils.c:531:9: runtime error: call to function handle_variant_args through pointer to incorrect function type 'void (*)(void *, const char *, int, char **, int *)'
src/libavformat/hls.c:379: note: handle_variant_args defined here

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
(cherry picked from commit d768bd564e)
2026-09-19 17:00:29 +02:00
Michael Niedermayer
b2c3ad438c avformat/hlsenc: reject out-of-range EXT-X-PROGRAM-DATE-TIME
Parse the timestamp with av_small_strptime() instead of sscanf(): it
range-checks each field (year 0-9999, month, day, hour, minute, second)
and limits the number of digits consumed, so an oversized field can no
longer overflow during parsing. The mktime() result is additionally
checked for EOVERFLOW.

Fixes: integer overflow

Found-by: Kery (Qi Kery <qikeyu2001@outlook.com>)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit c82196b299)
2026-09-19 17:00:07 +02:00
Niklas Haas
4d58e9d8d4 avformat/http: only re-use old connection if valid
Otherwise, this might leak stale bytes that were already drained by the
HTTP soft-seek attempt.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
(cherry picked from commit 0d0f9a06ab)
2026-09-19 16:59:28 +02:00
Niklas Haas
cb4c0da19c avformat/http: properly re-set s->range_end before requests
Otherwise this could leak stale values from a previous response.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
(cherry picked from commit 8712114200)
2026-09-19 16:59:28 +02:00
Michael Niedermayer
6cebacddcc avformat/mpegts: Fix memleak of pes_filter.opaque
Fixes: 490257166/clusterfuzz-testcase-minimized-ffmpeg_dem_MPEGTS_fuzzer-4815675538604032

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit c25673fe70)
2026-09-19 16:59:28 +02:00
Linke
678672a786 avformat/av1: fix uvlc loop past end of bitstream
When get_bits_left() returns a negative value (bitstream reader already past the end of the buffer), the while condition while (get_bits_left(gb)) evaluates to true since any non-zero int is truthy.

With the safe bitstream reader enabled, get_bits1() returns 0 past the buffer end, so the break never triggers and leading_zeros increments toward INT_MAX.

Change the condition to > 0, consistent with skip_1stop_8data_bits() which already uses <= 0 for the same pattern.

Signed-off-by: Linke <1102336121@qq.com>
(cherry picked from commit e44d76f61f)
2026-09-19 16:59:28 +02:00
Christopher Decker
3765be13dc avformat/os_support: fix return value of win32_rename
The return value of MoveFileExW was not being correctly interpreted,
see https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexw.

On Windows a failed rename over the file: protocol now surfaces as failed to rename file %s to %s:
Operation not permitted (ff_rename, libavformat/avio.c:867) plus an AVERROR(EPERM) return, where previously the muxer
reported success and the user was left with a missing or stale output file and no diagnostic. This affects the
write-to-temp-then-rename paths in hlsenc, dashenc, hdsenc, smoothstreamingenc, segment, and img2enc (e.g. HLS/DASH
playlist updates, -write_temp_file, segment list finalization).

Also, added unit tests to exercise the rename function.

Signed-off-by: Christopher Decker <chris.decker08@gmail.com>
(cherry picked from commit 94ff335d76)
Co-Authored-by: Fable 5
2026-09-19 16:18:37 +02:00
Michael Niedermayer
113150ff56 avformat/genh: check for unsupported interlaved size 1 typ1 THP
Fixes: use of uninitialized memory
Fixes: crafted_malicious.genh / generate_poc.py
Fixes: XtWk54O0PGfP
Found-by: zhang xingxing

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 4ebb720fc1)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:20 +02:00
jiangjie
7ba9579ae5 avformat/http: free cookie parameters on parse failure
Fixes issue #24172

(cherry picked from commit 89153eb701)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:19 +02:00
Steven Liu
400fe9454f avformat/dashdec: check fragment_timescale before division in refresh_manifest
fix issue: issues/23057 POC4

In refresh_manifest(), when timelines are present, fragment_timescale is
used as the denominator to compute currentTime. If fragment_timescale is
zero (e.g., timescale attribute missing from a crafted manifest with
SegmentTimeline), this results in a division by zero.

Add fragment_timescale > 0 guard to both the video and audio timeline
processing paths to prevent the crash.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
(cherry picked from commit 6a351a3113)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:17 +02:00
unfunnyatearug
1aa713eeb8 avformat/genh: check thp extradata read and allocation
the genh demuxer had the same short-read issue at one location. the read is now performed with `ffio_read_size()` so truncated input is rejected instead of leaving uninitialized data in the extradata.
`ff_alloc_extradata()` also had its return value unchecked. if allocation failed, the code could dereference a null pointer. the return value is now checked.
the affected path is capped at two channels, so the potential information leak is relatively small, but it is the same underlying bug class.

Signed-off-by: unfunnyatearug <yalisib2222@gmail.com>
(cherry picked from commit 4b47405e1c)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:17 +02:00
zhorzhetta1404-ux
b305f8cdc9 avformat/oggdec: check for integer overflow in buf_realloc
In buf_realloc, os->bufsize is unsigned int and the code doubles it:
    nb = av_realloc(os->buf, 2*os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE);

When os->bufsize exceeds UINT_MAX/2, the multiplication overflows
to a small value, av_realloc returns a tiny buffer, and the subsequent
page write in ogg_read_page goes out of bounds.

Reject the reallocation before the overflow can occur. The largest
safe value is (UINT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) / 2.

Signed-off-by: age5000 <age5000@proton.me>
(cherry picked from commit d7d119bbe2)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:17 +02:00
Michael Niedermayer
5f204c60f1 avformat/mov: Allocate the array without clearing before read
Fixes: OOM
Fixes: poc-keys-count-16777216-inflated-sizes.mp4
Fixes: hKO4f7GYoUd0
(cherry picked from commit 01c3721851)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:15 +02:00
Michael Niedermayer
05c0c7f765 avformat/mov: do not zero a key string before reading it
Fixes: OOM
Fixes: poc-keys-bigkey-256M.mp4
Fixes: hKO4f7GYoUd0
(cherry picked from commit 3afa5444a3)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:15 +02:00
He Huang
9992edfe9f avformat/mov: bound the keys atom entry count by the atom size
mov_read_keys() allocated (count + 1) pointers from the 32 bit entry
count of the keys atom before reading a single key record, so a 56 byte
file declaring 16777216 keys made ffprobe allocate and zero 128 MiB.
Every key record takes at least 8 bytes, so a count above atom.size / 8
cannot be satisfied and is rejected before the allocation.

Fixes: unbounded allocation
Fixes: poc-keys-count-16777216.mp4
Fixes: hKO4f7GYoUd0
Found-by: He Huang, discovery assisted by NexusSan
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 67926e6667)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:14 +02:00
Joshua Rogers
0cd2a70eac avformat/tls_mbedtls: set the expected hostname for numeric hosts
For IP-literal hosts mbedtls_ssl_set_hostname() was skipped, so a
CA-trusted certificate for an unrelated name was accepted with no CN/SAN
check. Set the name for numeric hosts too; mbedTLS matches IP literals
against iPAddress SANs.

Fixes: certificate host mismatch accepted for IP-literal hosts (CWE-297)
Fixes: oLS26nsaOqUr
Found-by: Joshua Rogers <joshua.rogers@aisle.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 57a2e704b4)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:13 +02:00
Jun Zhao
b3c76bbed6 avformat/vpk: Check the channel count before dividing in the last block
vpk_read_packet() divides last_block_size and block_align by
codecpar->ch_layout.nb_channels when assembling the last interleaved
block. Header parsing already rejects a non-positive channel count,
but a failed avcodec_open2() can later zero the layout through
ff_codec_close() -> av_opt_free(), so the division is reached with a
zero divisor.

Check the channel count again before dividing and return
AVERROR_INVALIDDATA.

Original-patch-by: Kacper Michajłow <kasper93@gmail.com>
Fixes: #24290
Reported-by: Darío Clavijo
Found-by: OSS-Fuzz
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
(cherry picked from commit 780f6efbcf)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:12 +02:00
Jun Zhao
8bf82c567a avformat: Restore the container channel layout after a failed decoder open
avformat_find_stream_info() copies codec parameters from the decoder
context after probing, including when avcodec_open2() has already
failed. A failed avcodec_open2() zeroes the context channel layout via
ff_codec_close() -> av_opt_free(), because ch_layout is an
AV_OPT_TYPE_CHLAYOUT option. That empty layout is then written back
onto codecpar and replaces the value the demuxer had already set from
the container.

This is reachable for codecs such as adpcm_psx that have no parser and
do not set AVSTREAM_PARSE_*: the only source of the channel count is
the demuxer header. It differs from codecs like mp3, where the decoder
is expected to fill the layout.

Restore the container channel layout when it was specified and the
decoder result is unspecified, matching the existing restore of color
metadata in parameters_from_context().

See also:
https://ffmpeg.org/pipermail/ffmpeg-devel/2024-November/335598.html

Fixes: #24290
Fixes: https://issues.oss-fuzz.com/issues/42536474
Reported-by: Darío Clavijo
Found-by: OSS-Fuzz
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
(cherry picked from commit fd6dc624be)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:11 +02:00
Michael Niedermayer
c00cf360a3 avformat/sierravmd: require a 6bit palette in the probe
vmdvideo_decode_init() loads a 768 byte VGA palette from header offset
28 and scales each entry by 4, so every one of these bytes is 6bit in a
file that carries a video stream. Rejecting a larger value keeps raw
video from being mistaken for VMD: a yuv420p10le file starting with
0x2e 0x03 matches the header size field and then scores the same 50 as
the rawvideo demuxer picked by the .yuv extension, which leaves the
format undetermined and fails the whole conversion.

The 26 files with a video stream on samples.ffmpeg.org/game-formats/
sierra-vmd/ all pass; the 9 audio only ones there hold unrelated data
at offset 28 and are exempted by the width and height test.

Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/22284
(cherry picked from commit 905ef92f02)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:11 +02:00
Paulo Cabral Sanz
e2e5e8d2da avformat/binka: reject truncated packet reads
binka_read_packet() calls avio_read() into a buffer from av_new_packet()
and ignores the return value. packet_alloc() only zeroes the 64-byte
padding; the payload is left uninitialized.

pkt_size is avio_rl16() + 4 (max 65539). On a truncated file the demuxer
still returns 0, so av_read_frame delivers up to 64 KiB of uninitialized
heap per packet. ffmpeg -c copy writes those bytes into the output.

Use ffio_read_size() so a short read fails the packet with
AVERROR_INVALIDDATA. Same class as 29f513a (fsb) and 4b47405 (genh).

Signed-off-by: Paulo Cabral Sanz <paulosanz@poli.ufrj.br>
(cherry picked from commit c2394a0ff3)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:11 +02:00
jiangjie
01d7854d49 avformat/dashenc: free http options on avio_open_dyn_buf failure
Fixes #24171

(cherry picked from commit ade01193a1)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:09 +02:00
Kacper Michajłow
09f3d21552 avformat/wvdec: convert flags to defines
Don't use values that would extend emum data size.

Fixes: warning: enumerator value which exceeds the range of 'int' is a
       C23 extension (2147483648 is too large)

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
(cherry picked from commit e7b9c5fe77)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:09 +02:00
Michael Niedermayer
7fce6dd8e6 avformat/mlv: end the LJ92 packet where its data ends
Fixes: read of uninitialized memory
Fixes: PJaSVrRTt6Kf
Found-by: Eunsoo Kim, Microsoft FORGE Labs
(cherry picked from commit 73130e77dc)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:08 +02:00
Michael Niedermayer
cf30e0e4d1 avformat/mpegts: reject a max_packet_size below one TS payload
Fixes:  ffmpeg -max_packet_size 100 -i fate-suite/mpegts/h264small.ts -f null -

Fixes: out of array access
Fixes: eYvYXUJZbPJ
Regression since: bca30570d2
Found-by: Eunsoo Kim, Microsoft FORGE Labs

(cherry picked from commit 37721094ab)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:08 +02:00
Michael Niedermayer
2d8f25f0fc avformat/mpegts: keep the PES payload within max_packet_size
Fixes: out of array access
Fixes: eYvYXUJZbPJ
Regression since: bca30570d2
Found-by: Eunsoo Kim, Microsoft FORGE Labs

(cherry picked from commit c42ac5c566)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:08 +02:00
Joshua Rogers
1e565c3e99 avformat/rtpenc_av1: do not narrow the OBU size to (long)
(long)obu_size sign-flips values in 0x80000000..0xfffffffd on ILP32/LLP64
targets (32-bit long, e.g. 64-bit Windows), bypassing the size check.
Compare as uint32_t; frame_size is non-negative at this point.

No PoC as the used setup was 64bit specific

(cherry picked from commit b4c199c590)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:07 +02:00
Michael Niedermayer
66aec442f6 avformat/rtpenc_av1: Check num_lebs
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit d862937c5a)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:07 +02:00
Joshua Rogers
0353c8d5d3 avformat/rtpenc_av1: bound OBU size in the keyframe search loop
The is_keyframe sequence-header search loop advanced buf_ptr/rem_size by
num_lebs + obu_size without bounding obu_size against the remaining data
(unlike the main packetization loop). A crafted obu_size (~0x80000010)
wraps the signed rem_size back positive, so the next iteration
dereferences a pointer past the packet. Consume the LEB bytes first, then
reject an OBU larger than the remaining size. Out-of-bounds read reachable
from a crafted AV1 packet muxed to RTP.

Fixes: out of array read
(cherry picked from commit 983dae9c19)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:07 +02:00
Anxious Koisi
d3384056a5 avformat/gopher: Fix CRLF injection
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit f925849484)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:07 +02:00
Joshua Rogers
be8a4974e8 avformat/rtpenc_vc2hq: reject data units larger than the RTP payload buffer
send_packet() copied an input-derived unit/fragment size into the fixed
rtp_ctx->buf with no bound, overflowing it for a crafted Dirac unit even at
the default packet size. Reject units that do not fit in max_payload_size.

Fixes: out of array access
(cherry picked from commit 1cdeb3c4e7)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:07 +02:00
Joshua Rogers
62d4ca1f3e avformat/dashdec: reject a negative fragment index
A live manifest whose startNumber decreases across a refresh drives
cur_seq_no negative in move_segments(); get_current_fragment() only checked
the upper bound before indexing fragments[]. Add a lower-bound check and
clamp the negative delta at its source.

Fixes: out of array read
(cherry picked from commit 65b0dab903)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:06 +02:00
Joshua Rogers
bce1d48612 avformat/hevc: reject hvcC NAL arrays that overflow the 16-bit count
numNalus is uint16_t; a crafted hvcC declaring >65535 NAL units of one
type wraps it to 0 and then writes nal[-1]. Reject before the count can
wrap. Reachable by remuxing a crafted file with -c copy.

Fixes: integer overflow
Fixes: out of array access
(cherry picked from commit acf5d7cdc1)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:06 +02:00
Joshua Rogers
3193e03201 avformat/mpegenc: reject stream counts that overflow the system header
put_system_header() writes 12 + 3*N bytes after the pack header into a
fixed 128-byte stack buffer, but is handed a PutBitContext sized past the
real buffer, so its own bounds check never fires; ~35+ streams overflow the
stack. Reject at mux init when the system header would not fit.

Fixes: out of array access
Fixes: many.mkv
(cherry picked from commit 9d786e4b5e)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:06 +02:00
Michael Niedermayer
0202a564a4 avformat/mpegenc: pass buffer size into put_system_header()
Fixes: out of array access
Fixes: many.mkv

Found-by: Joshua Rogers <joshua.rogers@aisle.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit cf39fd2fa8)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:06 +02:00
Joshua Rogers
4e1b9a41ba avformat/librist: honor the caller buffer size in librist_read
librist_read() ignored its size argument and copied the full payload_len,
overflowing a smaller destination (e.g. via the async: wrapper). Clamp the
copy to the caller-provided buffer size.

Fixes: out of array access
(cherry picked from commit 1c10bcc2e1)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:06 +02:00
qaq03101
5907f16395 avformat/scd: reject zero-channel tracks
A zero channel count can cause a division by zero in
scd_read_packet().

Reported-by: sdjasj
Fixes #23181.
Signed-off-by: qaq03101 <1440810736@qq.com>
(cherry picked from commit 9c176644aa)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:05 +02:00
Michael Niedermayer
105cf0187b avformat/rawutils: reject raw RGB frames that do not fit an AVPacket
Fixes: integer overflow
Fixes: out of array access
Fixes: payload.film
Fixes: czK1F83k3zvT
Found-by: Clouditera Security, Z.ai Security, NSFOCUS
(cherry picked from commit d3ad8a7fee)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:05 +02:00
Michael Niedermayer
950c813c02 avformat/mov: reject a trun sample count the input cannot hold
Fixes: OOM
Fixes: 525088811/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5229499332231168
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
(cherry picked from commit ae0e0ba3c3)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:04 +02:00
Steven Liu
00cf190567 avformat/dashdec: check NULL pointer before use str_end_offset
fix issue: issues/23057 POC2

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
(cherry picked from commit 5e0ca682a4)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:03 +02:00
Steven Liu
1623497c7a avformat/dashdec: check NULL pointer of av_strtok value before use it
fix issue: issues/23057 POC1
release seg memory and return NULL if av_strtok return NULL.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
(cherry picked from commit 813c28d1ce)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:03 +02:00
Steven Liu
3651d59e2b avformat/dashdec: fix integer truncation in calc_max_seg_no()
When computing the segment count for a SegmentTimeline entry with
repeat="-1" (indefinite repeat, typical for live streams), the
expression:

  length_of_each_segment = pls->timelines[i]->duration /
                           pls->fragment_timescale;
  num = c->period_duration / length_of_each_segment;

performs two successive integer divisions.  The first division
truncates toward zero; if the segment duration in timescale ticks
is smaller than the timescale (duration < fragment_timescale),
length_of_each_segment becomes 0, and the second division triggers
a division by zero.

Fix this by using av_rescale(), which computes

  period_duration * fragment_timescale / duration

with 64-bit intermediate precision, avoiding both the truncation
and the zero-division risk.  If duration is 0 (invalid manifest),
explicitly fall back to first_seq_no instead of crashing.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
(cherry picked from commit 0c0dd61b8f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:03 +02:00