Skip to content

Commit 9a2cff6

Browse files
Merge pull request #9286 from MarkLee131/fix/quicktime-setmediastream-bound
Bound setMediaStream search to the trak atom size
2 parents 3e65eb2 + 6aef39d commit 9a2cff6

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

include/exiv2/quicktimevideo.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ class EXIV2API QuickTimeVideo : public Image {
183183
/*!
184184
@brief Recognizes which stream is currently under processing,
185185
and save its information in currentStream_ .
186+
@param atom_size Full size of the atom currently being processed, in bytes,
187+
including both the atom header and its payload.
186188
*/
187-
void setMediaStream();
189+
void setMediaStream(size_t atom_size);
188190
/*!
189191
@brief Used to discard a tag along with its data. The Tag will
190192
be skipped and not decoded.

src/quicktimevideo.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ void QuickTimeVideo::tagDecoder(Exiv2::DataBuf& buf, size_t size, size_t recursi
645645
fileTypeDecoder(size);
646646

647647
else if (equalsQTimeTag(buf, "trak"))
648-
setMediaStream();
648+
setMediaStream(size);
649649

650650
else if (equalsQTimeTag(buf, "mvhd"))
651651
movieHeaderDecoder(size);
@@ -1126,13 +1126,18 @@ void QuickTimeVideo::NikonTagsDecoder(size_t size) {
11261126
io_->seek(cur_pos + size, BasicIo::beg);
11271127
} // QuickTimeVideo::NikonTagsDecoder
11281128

1129-
void QuickTimeVideo::setMediaStream() {
1129+
void QuickTimeVideo::setMediaStream(size_t atom_size) {
11301130
size_t current_position = io_->tell();
1131+
size_t search_end = Safe::add(current_position, atom_size);
1132+
if (search_end > io_->size())
1133+
search_end = io_->size();
11311134
DataBuf buf(4 + 1);
11321135

1133-
while (!io_->eof()) {
1136+
while (!io_->eof() && Safe::add(io_->tell(), size_t{4}) <= search_end) {
11341137
io_->readOrThrow(buf.data(), 4);
11351138
if (equalsQTimeTag(buf, "hdlr")) {
1139+
if (Safe::add(io_->tell(), size_t{12}) > search_end)
1140+
break;
11361141
io_->readOrThrow(buf.data(), 4);
11371142
io_->readOrThrow(buf.data(), 4);
11381143
io_->readOrThrow(buf.data(), 4);

0 commit comments

Comments
 (0)