Skip to content
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

leb128() contradicting constraints #356

Open
podborski opened this issue Aug 27, 2024 · 6 comments
Open

leb128() contradicting constraints #356

podborski opened this issue Aug 27, 2024 · 6 comments

Comments

@podborski
Copy link

I see two contradicting statements in the definition of leb128().

It is a requirement of bitstream conformance that the value returned from the leb128 parsing process is less than or equal to (1 << 32) - 1.

constricts with

It is a requirement of bitstream conformance that the most significant bit of leb128_byte is equal to 0 if i is equal to 7. (This ensures that this syntax descriptor never uses more than 8 bytes.)

First statement limits the number of bytes to 5. Second says that the limit is 8. I guess the first one wins :)

@agrange
Copy link
Collaborator

agrange commented Aug 27, 2024 via email

@agrange
Copy link
Collaborator

agrange commented Aug 27, 2024 via email

@wantehchang
Copy link
Collaborator

The first requirement was added later. It was added to make it possible to store a leb128 value in size_t, whether size_t is 32 or 64 bits.

The Note in that section explains why the two requirements do not contradict each other:

Note: There are multiple ways of encoding the same value depending on how many leading zero bits are encoded. There is no requirement that this syntax descriptor uses the most compressed representation. This can be useful for encoder implementations by allowing a fixed amount of space to be filled in later when the value becomes known.

So, the first requirement does NOT limit the number of bytes to 5.

@agrange
Copy link
Collaborator

agrange commented Aug 27, 2024 via email

@podborski
Copy link
Author

But leb128() is always byte-aligned. I'm not so sure I understand the use-case where you would need more than 5 bytes in leb128(). Are there any examples of where non-compact representation is used?

@agrange
Copy link
Collaborator

agrange commented Aug 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants