Skip to content

compress.zlib: changed to pure V RFC-compliant code#27189

Open
JalonSolov wants to merge 6 commits into
vlang:masterfrom
JalonSolov:pure_v_zlib
Open

compress.zlib: changed to pure V RFC-compliant code#27189
JalonSolov wants to merge 6 commits into
vlang:masterfrom
JalonSolov:pure_v_zlib

Conversation

@JalonSolov
Copy link
Copy Markdown
Collaborator

Also has interop subdir with code for full V<->C<->Python cross-validation.

Copy link
Copy Markdown

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

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: 08a756f861

ℹ️ 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/zlib/zlib.v
@JalonSolov
Copy link
Copy Markdown
Collaborator Author

JalonSolov commented May 19, 2026

The last commit fixed a bug in embed_file that's been there a long time, but miniz allowed it to work. It was caught because this zlib code is stricter than miniz.

It didn't fail unless you used -prod to compile your code.

Why it only failed in -prod

In -prod, embedded files are loaded from the generated static blob table, and compressed embeds use the compressed path.

Outside -prod, the same compressed-embed runtime path wasn't followed, so the bug didn’t show up the same way.

Why the new zlib code exposes it

The previous miniz-backed path was more forgiving and could ignore junk after the DEFLATE stream.

The new code is stricter (per the RFC) and now rejects malformed zlib containers where extra bytes appear between the end of the DEFLATE payload and the final Adler-32 footer

So the stricter decoder exposed a bug that was already present in the caller.

Fix

The runtime needed to remember the compressed length separately from the uncompressed length.
In practice:

  • added a compressed_len field to EmbedFileData
  • set it from compressed_bytes.len in gen/c/embed.v
  • used that compressed length in ed.compressed.vbytes(...)

Before this fix, the code only stored one len, and that value was being used for the wrong purpose.

@medvednikov medvednikov reopened this May 19, 2026
@JalonSolov
Copy link
Copy Markdown
Collaborator Author

Note that the v -silent vlib/v/gen/c/coutput_test.v that's failing in CI, runs fine on Linux.

I don't have a Windows system to test on. No BSD systems, either. I'll look into a docker container, qemu, etc. unless someone else can take a look...

@medvednikov medvednikov reopened this May 21, 2026
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