Skip to content

[1.x] KaxBlock: rework EBML lacing sizes in SCOPE_PARTIAL_DATA mode#237

Open
robUx4 wants to merge 4 commits into
Matroska-Org:v1.xfrom
robUx4:1x-partial-ebml-lacing
Open

[1.x] KaxBlock: rework EBML lacing sizes in SCOPE_PARTIAL_DATA mode#237
robUx4 wants to merge 4 commits into
Matroska-Org:v1.xfrom
robUx4:1x-partial-ebml-lacing

Conversation

@robUx4

@robUx4 robUx4 commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

We only read the bytes that correspond to frame sizes, rather
than a guesstimate of how much data we are going to need.

That's what the SCOPE_PARTIAL_DATA mode is about. This is already the case
for LACING_XIPH. And we don't need a buffer allocation.

And throw when the EBML length difference gives a negative frame length.

@robUx4 robUx4 added the bug label Apr 28, 2026
Comment thread src/KaxBlock.cpp Outdated

@mbunkus mbunkus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The changes are fine IMO & pass my test suite. I only have to small requests, posted at appropriate places.

Comment thread src/KaxBlock.cpp Outdated
Result += input.read(cursor, FrameNum*4);
FrameSize = ReadCodedSizeValue(cursor, SizeRead, SizeUnknown);
{
auto EBMLCodecLength = [](binary buf) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd prefer this to be a top-level function in an anonymous namespace. There's really no need to make it a lambda; it only makes the function longer & slightly harder to read. Thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I created a static function on top of the file. IMO that's something that should be provided by libebml. But I guess that should be for the v2.0.

Comment thread src/KaxBlock.cpp Outdated
if (FrameNum == 0)
Index = 0;
else {
binary length_buf[8];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you please fix the indentation of this whole block? Thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

robUx4 added 4 commits July 6, 2026 09:05
We only read the bytes that correspond to frame sizes, rather
than a guesstimate of how much data we are going to need.

That's what the SCOPE_PARTIAL_DATA mode is about. This is already the case
for LACING_XIPH. And we don't need a buffer allocation.
The spec [^1] is not clear whether when there is a single frame in the lace
the size of the frame should be written. However it is forbidden to put
a single frame in a lace [^2]. libmatroska doesn't support it.
libavformat doesn't support lacing writing.
However the last frame size is never written in any lace, so that's the
first one when there's only one frame.

[^1]: https://www.rfc-editor.org/rfc/rfc9559#section-10.3.3
[^2]: https://www.rfc-editor.org/rfc/rfc9559#section-10.3
No functional changes.
@robUx4 robUx4 force-pushed the 1x-partial-ebml-lacing branch from 66e4f59 to 6445cef Compare July 6, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants