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

enhance: add supposer for zstd skippable frames #39

Closed
wants to merge 3 commits into from
Closed

Conversation

bojand
Copy link
Owner

@bojand bojand commented Apr 12, 2021

Comment on lines +209 to +211
let magic = u32::from_le_bytes(buf[0..4].try_into().unwrap()) as usize;
if magic & ZSTD_SKIP_MASK == ZSTD_SKIP_START {
let data_len = u32::from_le_bytes(buf[4..8].try_into().unwrap()) as usize;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Converting it into a u32 and then casting it to usize feels very fragile to me, and would definitely break on 16 bit systems (which I have zero knowledge in, but infer could probably run perfectly on them otherwise). It also adds the ambiguity of what happens on big endian platforms. I think we should compare slices directly.

Copy link
Owner Author

Choose a reason for hiding this comment

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

👋 Sorry been distracted with a lot of other commitments.
It's been a while since I looked at this (and worked with Rust) so my context might be rusty, and I might be missing something, but wanted to try and return to this slowly...

According to the docs the magic number is 4 bytes and little endian, the frame size is 4 bytes, little-endian format, unsigned 32-bits as well. So it would seem this is the required data layout regardless of the underlying architecture, and we need to be able to load and inspect the size as 32 bit unsigned int in order to fully support the possible data size? So perhaps this should be behind feature flag / conditional compilation? Are there other work arounds?

Copy link
Contributor

Choose a reason for hiding this comment

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

The solution would be to size-check when converting u32->usize.

impl TryFrom<u32> for usize does exactly what you want, it never fails on 32 and 64-bit machines, but might fail on 16-bit ones.

I see that you've been busy (btw, ghz is pretty cool!) and this PR was hanging for long, so I re-made the PR with the fixes needed, I hope you don't mind.

#88

@marcospb19
Copy link
Contributor

@bojand I believe you can close this now

@bojand bojand closed this Jun 22, 2023
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

Successfully merging this pull request may close these issues.

None yet

3 participants