Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/matroskavideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -659,11 +659,11 @@ void MatroskaVideo::decodeBlock() {
return;
}

io_->read(buf, 1);
io_->readOrThrow(buf, 1, ErrorCode::kerCorruptedMetadata);
Comment on lines 660 to +662
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decodeBlock() still uses io_->read(buf, 1) for the first byte and only checks eof(). 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 and io_->error(), or switching to readOrThrow() with a special-case for clean EOF (0 bytes + eof()) to stop traversal.

Copilot uses AI. Check for mistakes.
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())
Expand All @@ -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
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new readOrThrow() paths change truncated-file behavior from “silently continue with stale/partial data” to “throw kerCorruptedMetadata”. Since there are existing gtest unit tests for MatroskaVideo, it would be good to add a regression test that feeds a minimal valid MKV header followed by a truncated element and asserts readMetadata() throws (and does not populate metadata).

Copilot uses AI. Check for mistakes.
switch (tag->_type) {
case InternalField:
decodeInternalTags(tag, buf2.data());
Expand Down
Loading