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

node:zlib module has numerous bugs, inconsistencies, and errors #20516

Closed
nberlette opened this issue Sep 15, 2023 · 4 comments · Fixed by #21756
Closed

node:zlib module has numerous bugs, inconsistencies, and errors #20516

nberlette opened this issue Sep 15, 2023 · 4 comments · Fixed by #21756
Labels
bug Something isn't working correctly good first issue Good for newcomers node compat

Comments

@nberlette
Copy link
Contributor

nberlette commented Sep 15, 2023

I've noticed quite a few issues with the node:zlib implementation. Wasn't sure if I should open them up in individual issues, but decided to just do it unified since they're all related to the same module.

First off, I'd like to reference the official Node.js documentation on their zlib module. Note that the accepted input types by all convenience methods is Buffer | TypedArray | DataView | ArrayBuffer | string.

  1. brotli compression fails on data > 4096B (fixed in fix(ext/node/ops/zlib/brotli): Allow decompressing more than 4096 bytes #20301)

  2. zlib.brotliCompressSync only accepts inputs that are Buffer, TypedArray, or string. It accepts all types of TypedArray, it seems, but DataViews and ArrayBuffers cause it to throw a vague Failed to compress exception. Inconsistent with the expected behavior above. See below for a screenshot.

Screenshot 2023-09-15 at 8 54 16 AM
  1. zlib.brotliCompress returns what appears to be a native Uint8Array, rather than a Node.js Buffer like its synchronous counterpart. Definitely inconsistent behavior, and it gets more inconsistent when trying different input types. Any type other than a Buffer, string, or Uint8Array throws an error saying it "was not a typed ArrayBufferView".... which is not true. See below.
Screenshot 2023-09-15 at 8 55 41 AM
  1. The non-brotli convenience functions all seem to throw their own errors that have no discernable pattern or logic when it comes to which binary types should be allowed and which should be banned. Here's another screenshot showing gzip and gzipSync's erratic behavior:
Screenshot 2023-09-15 at 9 03 28 AM

I'd spend more time and document the behavior on each of the remaining methods but unfortunately I'm out of time right now. I'll try to follow this up with additional info and (hopefully) a PR, if I'm able to squeeze in a fix for this tonight/tomorrow.

Thanks!

@lucacasonato lucacasonato added bug Something isn't working correctly good first issue Good for newcomers node compat labels Sep 15, 2023
@lucacasonato
Copy link
Member

It looks like all is needed here is some massaging of input types into the correct forms for the internal algorithms, and the right output types for the reverse.

Sounds like a good first issue. @nberlette if you want to grab it, feel free, otherwise someone else can jump in (just remember to update on this issue if you are working on it as to not duplicate work!)

@dsherret
Copy link
Member

Probably related: #20456

@nberlette
Copy link
Contributor Author

@lucacasonato Thanks for the reply Luca, I'll take a stab at it tonight! Based on your response it sounds like it should be pretty straihtforward to sort out. But forgive me in advance for any late-night pings you may get if I find myself lost in internal Deno-API-land 😅.

@dsherret Thanks for bringing that issue in! Definitely seems to be related, thats some of the same behavior I've taken note of myself. I could swear I opened that issue up when I was searching for priors before making this post... I was in a rush though so I must've overlooked it. My bad.

I'll cc you guys in the PR when I get it pushed through. Have a great weekend!

@nberlette
Copy link
Contributor Author

Hey @lucacasonato, hope all is well. I've been progressing on a PR for the zlib module, but other unexpected commitments took priority the last couple weeks. Apologies for the delays.

As this is my first real contribution here (aside from a few very small fixes in the past), I have a couple questions on aligning my changes with the codebase. Could you spare a few minutes to chat outside of GitHub, maybe via Discord or email?

Thanks for your patience,
Nick

littledivy pushed a commit that referenced this issue Dec 31, 2023
This fixes point 2 of #20516 

This adds a conversion from Dataview/Buffer by returning `obj.buffer`
which can be converted to a `UInt8Array`.

Question: Regarding point 4 of the mentioned issue would it be
appropriate to copy the toU8 helper to the `zlib.mjs` methods?
littledivy pushed a commit that referenced this issue Dec 31, 2023
This fixes point 3 of #20516

This PR creates consistency between the sync and async versions of the
brotli compress where we will always return a buffer like Node.
littledivy pushed a commit that referenced this issue Jan 3, 2024
Fixes #20516 
Follow up to #21747 and #21746

This tackles the last point of #20516 where certain inputs weren't
accepted in the other zlib methods

This adds the `toU8` conversion of `_brotli` to `_zlib.mjs`, when we
create the ZLibBuffer, we'll sanitize the input. I noticed that the
async had no handler for `string` input so I added that as well.
bartlomieju pushed a commit that referenced this issue Jan 4, 2024
This fixes point 2 of #20516 

This adds a conversion from Dataview/Buffer by returning `obj.buffer`
which can be converted to a `UInt8Array`.

Question: Regarding point 4 of the mentioned issue would it be
appropriate to copy the toU8 helper to the `zlib.mjs` methods?
bartlomieju pushed a commit that referenced this issue Jan 4, 2024
This fixes point 3 of #20516

This PR creates consistency between the sync and async versions of the
brotli compress where we will always return a buffer like Node.
bartlomieju pushed a commit that referenced this issue Jan 4, 2024
Fixes #20516 
Follow up to #21747 and #21746

This tackles the last point of #20516 where certain inputs weren't
accepted in the other zlib methods

This adds the `toU8` conversion of `_brotli` to `_zlib.mjs`, when we
create the ZLibBuffer, we'll sanitize the input. I noticed that the
async had no handler for `string` input so I added that as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly good first issue Good for newcomers node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants