-
Notifications
You must be signed in to change notification settings - Fork 317
Use readOrThrow in MatroskaVideo::decodeBlock for EOF detection #9282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -642,7 +642,7 @@ void MatroskaVideo::decodeBlock() { | |
|
|
||
| uint32_t block_size = findBlockSize(buf[0]); // 0-8 | ||
| if (block_size > 0) | ||
| io_->read(buf + 1, block_size - 1); | ||
| io_->readOrThrow(buf + 1, block_size - 1, ErrorCode::kerCorruptedMetadata); | ||
|
|
||
| auto tag_id = returnTagValue(buf, block_size); | ||
| const MatroskaTag* tag = Exiv2::find(matroskaTags, tag_id); | ||
|
|
@@ -659,11 +659,11 @@ void MatroskaVideo::decodeBlock() { | |
| return; | ||
| } | ||
|
|
||
| io_->read(buf, 1); | ||
| io_->readOrThrow(buf, 1, ErrorCode::kerCorruptedMetadata); | ||
| block_size = findBlockSize(buf[0]); // 0-8 | ||
|
|
||
| if (block_size > 0) | ||
| io_->read(buf + 1, block_size - 1); | ||
| io_->readOrThrow(buf + 1, block_size - 1, ErrorCode::kerCorruptedMetadata); | ||
| size_t size = returnTagValue(buf, block_size); | ||
|
|
||
| if (tag->isComposite() && !tag->isSkipped()) | ||
|
|
@@ -683,7 +683,7 @@ void MatroskaVideo::decodeBlock() { | |
| } | ||
|
|
||
| DataBuf buf2(bufMaxSize + 1); | ||
| io_->read(buf2.data(), size); | ||
| io_->readOrThrow(buf2.data(), size, ErrorCode::kerCorruptedMetadata); | ||
|
Comment on lines
684
to
+686
|
||
| switch (tag->_type) { | ||
| case InternalField: | ||
| decodeInternalTags(tag, buf2.data()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decodeBlock()still usesio_->read(buf, 1)for the first byte and only checkseof(). If the read fails due to an I/O error (e.g.,ferror) without setting EOF,buf[0]can remain uninitialized and the subsequent tag parsing will use garbage. Consider checking the returned byte count andio_->error(), or switching toreadOrThrow()with a special-case for clean EOF (0 bytes +eof()) to stop traversal.