node:zlib: zstd ignores an ArrayBuffer dictionary and does not reject a dictionary of a wrong type (Node v26.10.0 does) · Issue #44258 · oven-sh/bun · GitHub
Skip to content

node:zlib: zstd ignores an ArrayBuffer dictionary and does not reject a dictionary of a wrong type (Node v26.10.0 does) #44258

Closed as not planned

Description

@robobun

What happens

The zstd classes of node:zlib ignore a dictionary option that is not a Buffer, TypedArray or DataView. Node v26.10.0 uses an ArrayBuffer dictionary and throws ERR_INVALID_ARG_TYPE for each other type.

bun matches Node v26.3.0 here. Node changed two times after that:

  • v26.7.0 accepts an ArrayBuffer (nodejs/node#64599, "zlib: accept ArrayBuffer dictionary in Zstd").
  • v26.10.0 throws for the other types (commit 5e55085bc1, "zlib: reject invalid zstd dictionaries", from nodejs/node#65867).

Reproduction

const zlib = require("node:zlib");
const dictionary = Buffer.from(
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
    "Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
);
const input = Buffer.alloc(2000, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. ");
console.log("view dictionary:", zlib.zstdCompressSync(input, { dictionary }).length, "bytes");
console.log("no dictionary:", zlib.zstdCompressSync(input).length, "bytes");

const arrayBuffer = dictionary.buffer.slice(dictionary.byteOffset, dictionary.byteOffset + dictionary.byteLength);
for (const [label, value] of [
  ["ArrayBuffer", arrayBuffer],
  ["string", "a string"],
  ["number", 42],
  ["null", null],
]) {
  try {
    const stream = zlib.createZstdCompress({ dictionary: value });
    console.log(label + ":", stream._processChunk(input, zlib.constants.ZSTD_e_end).length, "bytes");
  } catch (e) {
    console.log(label + ": throws", e.code);
  }
}

Node v26.10.0:

view dictionary: 20 bytes
no dictionary: 76 bytes
ArrayBuffer: 20 bytes
string: throws ERR_INVALID_ARG_TYPE
number: throws ERR_INVALID_ARG_TYPE
null: throws ERR_INVALID_ARG_TYPE

bun 1.4.3 canary and Node v26.3.0:

view dictionary: 20 bytes
no dictionary: 76 bytes
ArrayBuffer: 76 bytes
string: 76 bytes
number: 76 bytes
null: 76 bytes

createZstdDecompress has the same difference.

Where

The Zstd constructor passes the dictionary to the native handle only when it is a view:

bun/src/js/node/zlib.ts

Lines 841 to 850 in 542f52b

The Brotli constructor in the same file already converts an ArrayBuffer and throws for the other types.

Activity

  1. Jarred-Sumner commented on Oct 8, 2026

    @Jarred-Sumner
    Collaborator

    Use handoff tool. GitHub issues are for user-facing issues and a user did not run into this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions