avcodec/dvdsub_parser: Fix length check for short packets
authorAidan MacDonald <aidanmacdonald.0x0@gmail.com>
Fri, 30 Sep 2022 14:20:09 +0000 (15:20 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Sun, 21 Jun 2026 15:59:33 +0000 (17:59 +0200)
commit280ceef4f9cb99d690db8358c6b59ac2a7547173
treeac6d101eb2bb57e393d04143e8c147576bf66986
parentb75afec43df5c068c619ba93ca66f752ba9c709f
avcodec/dvdsub_parser: Fix length check for short packets

The DVD subtitle parser handles two types of packets: "normal"
packets with a 16-bit length, and HD-DVD packets that set the
16-bit length to 0 and encode a 32-bit length in the next four
bytes. This implies that HD-DVD packets are at least six bytes
long, but the code didn't actually verify this.

The faulty length check results in an out of bounds read for
zero-length "normal" packets that occur in the input, which are
only 2 bytes long, but get misinterpreted as an HD-DVD packet.
When this happens the parser reads packet_len from beyond the
end of the input buffer. The subtitle stream is not correctly
decoded after this point due to the garbage packet_len.

Fixing this is pretty simple: fix the length check so packets
less than 6 bytes long will not be mistakenly parsed as HD-DVD
packets.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
(cherry picked from commit a4405cc0cc16413fe5222c888b3d4bb04cedc83f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/dvdsub_parser.c