Skip to content

Commit a057c4e

Browse files
committed
Make unknown block type emit all extension events
1 parent 323ef4b commit a057c4e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/reader/decoder.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -716,23 +716,22 @@ impl StreamingDecoder {
716716
goto!(0, ImageBlockStart, emit Decoded::BlockStart(Block::Image))
717717
}
718718
Some(Block::Extension) => {
719-
self.ext.data.clear();
720-
self.ext.sub_block_lens.clear();
721719
self.ext.id = AnyExtension(b);
722720
if !self.allow_unknown_blocks && self.ext.id.into_known().is_none() {
723721
return Err(DecodingError::format(
724722
"unknown extension block encountered",
725723
));
726724
}
727-
goto!(ExtensionBlockStart, emit Decoded::BlockStart(Block::Extension))
725+
goto!(ExtensionBlockStart)
728726
}
729727
Some(Block::Trailer) => {
730728
// The `Trailer` is the final state, and isn't reachable without extraneous data after the end of file
731729
goto!(Trailer, emit Decoded::BlockStart(Block::Trailer))
732730
}
733731
None => {
734732
if self.allow_unknown_blocks {
735-
goto!(ExtensionDataBlock(b as usize))
733+
self.ext.id = AnyExtension(0);
734+
goto!(0, ExtensionBlockStart)
736735
} else {
737736
Err(DecodingError::format("unknown block type encountered"))
738737
}
@@ -749,8 +748,11 @@ impl StreamingDecoder {
749748
}
750749
}
751750
ExtensionBlockStart => {
751+
self.ext.data.clear();
752+
self.ext.sub_block_lens.clear();
753+
self.ext.is_block_end = false;
752754
self.ext.sub_block_lens.push(b);
753-
goto!(ExtensionDataBlock(b as usize))
755+
goto!(ExtensionDataBlock(b as usize), emit Decoded::BlockStart(Block::Extension))
754756
}
755757
ExtensionDataBlock(left) => {
756758
if left > 0 {

0 commit comments

Comments
 (0)