Skip to content

Commit 4da5ac2

Browse files
authored
Fix writing too many offsets when updating MP4 stco/co64 atoms (#1332)
This will fix a DoS with a crafted MP4 file causing too many offsets to be written when updating the stco or co64 tables in MP4 files. Credits for the discovery of this bug go to Yuen Ying Ng (Ruth) (Cyber Security Researcher at PwC Hong Kong).
1 parent 193091f commit 4da5ac2

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

taglib/mp4/mp4tag.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ MP4::Tag::updateOffsets(offset_t delta, offset_t offset)
200200
unsigned int count = data.toUInt();
201201
d->file->seek(atom->offset() + 16);
202202
unsigned int pos = 4;
203-
while(count--) {
203+
const unsigned int maxPos = data.size() - 4;
204+
while(count-- && pos <= maxPos) {
204205
auto o = static_cast<offset_t>(data.toUInt(pos));
205206
if(o > offset) {
206207
o += delta;
@@ -220,7 +221,8 @@ MP4::Tag::updateOffsets(offset_t delta, offset_t offset)
220221
unsigned int count = data.toUInt();
221222
d->file->seek(atom->offset() + 16);
222223
unsigned int pos = 4;
223-
while(count--) {
224+
const unsigned int maxPos = data.size() - 8;
225+
while(count-- && pos <= maxPos) {
224226
long long o = data.toLongLong(pos);
225227
if(o > offset) {
226228
o += delta;

0 commit comments

Comments
 (0)