Skip to content

snappy: add Snappy compression - #26914

Merged
medvednikov merged 5 commits into
vlang:masterfrom
CG-SS:master
Apr 26, 2026
Merged

medvednikov merged 5 commits into
vlang:masterfrom
CG-SS:master

Conversation

@CG-SS

@CG-SS CG-SS commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

This adds a new module called snappy with a pure V Snappy implementation. It's basically a copy of this.

The pre-computed CRC32C remainders were generated using this script.

Since I couldn't really find any pre-compressed Snappy files that are used to test if a given implementation is correct, I just used this in order to create alice29_block.snappy and alice29_framing.snappy.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

πŸ’‘ Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56c2b4de35

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread vlib/compress/snappy/snappy_framing.v Outdated
Comment on lines +290 to +291
if dec.closed && dec.output.len == 0 {
return io.Eof{}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject EOF when decoder still has unparsed input

When StreamDecoder is closed, read() returns io.Eof{} solely based on output.len == 0, without checking whether buf still contains an incomplete header/body or whether the identifier was ever fully parsed. In practice, a truncated framed stream can be silently accepted in incremental mode: write() buffers the partial chunk, close() marks closed, and subsequent read() reports EOF instead of an error, which can hide data loss/corruption.

Useful? React with πŸ‘Β / πŸ‘Ž.

Comment on lines +393 to +395
val |= u32(b & 0x7f) << shift
if b & 0x80 == 0 {
return val, i, true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate 5th varint byte to prevent length overflow

read_uvarint accepts any terminating 5th byte and ORs (b & 0x7f) << shift into a u32 without overflow validation. For headers where the 5th byte has bits above 0x0f set (e.g. 0x10), the value wraps modulo 32 bits and is treated as valid instead of rejecting the header. This lets malformed Snappy blocks bypass invalid header varint checks and can produce incorrect declared output lengths.

Useful? React with πŸ‘Β / πŸ‘Ž.

@medvednikov

Copy link
Copy Markdown
Member

Thanks! Does it need to be in vlib or should it be installed via v install snappy ?

@CG-SS

CG-SS commented Apr 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! Does it need to be in vlib or should it be installed via v install snappy ?

I noticed that Vlang supports some compression algorithms out of the box and I simply assumed that there might be interest in Snappy, as it is widely used to perform streaming compression due to its framing format. I would say it depends on how many do you wish to support out of the box, and would be interesting to hear the reasoning for the current already supported ones.

@medvednikov
medvednikov merged commit a2be374 into vlang:master Apr 26, 2026
20 of 81 checks passed
@medvednikov

Copy link
Copy Markdown
Member

Merged, thanks!

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.

2 participants