Skip to content

zlib: zstdCompressSync() does not validate pledgedSrcSize #64600

Description

@Archkon

Version

latest main branch

Platform

7.1.3-arch1-3

Subsystem

zlib

What steps will reproduce the bug?

  const assert = require('node:assert/strict');
  const zlib = require('node:zlib');

  const input = Buffer.alloc(42);

  assert.throws(
    () => zlib.zstdCompressSync(input, {
      pledgedSrcSize: 1,
    }),
    {
      code: 'ZSTD_error_srcSize_wrong',
    },
  );

How often does it reproduce? Is there a required condition?

Every Time

What is the expected behavior? Why is that the expected behavior?

zstdCompressSync() should throw an error with:

  {
    code: 'ZSTD_error_srcSize_wrong',
    errno: zlib.constants.ZSTD_error_srcSize_wrong,
  }

What do you see instead?

Compression succeeds, causing assert.throws() to fail with

Additional information

The synchronous convenience API processes the input using the default final operation:

ZSTD_e_end

Therefore, its first compression call is effectively:

ZSTD_compressStream2(cctx, output, input, ZSTD_e_end);

Zstd has special behavior for this case. When the first call for a frame uses ZSTD_e_end, it replaces a previously configured pledged source size with the current input size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions