Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1683,8 +1683,16 @@ static uint32_t FastCRC32(v8::Local<v8::Value> receiver,
uint32_t value,
// NOLINTNEXTLINE(runtime/references)
v8::FastApiCallbackOptions& options) {
TRACK_V8_FAST_API_CALL("zlib.crc32");
v8::HandleScope handle_scope(options.isolate);
if (!data->IsArrayBufferView() && !data->IsString()) {
TRACK_V8_FAST_API_CALL("zlib.crc32.error");
THROW_ERR_INVALID_ARG_TYPE(
options.isolate,
"The \"data\" argument must be of type string or an instance of "
"Buffer, TypedArray, or DataView.");
return 0;
}
TRACK_V8_FAST_API_CALL("zlib.crc32");
return CRC32Impl(options.isolate, data, value);
}

Expand Down
12 changes: 12 additions & 0 deletions test/sequential/test-zlib-crc32-fast-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@
testFastPath();
testFastPath();

// Test that invalid input types throw after optimization
assert.throws(() => zlib.crc32(123), {
code: 'ERR_INVALID_ARG_TYPE',
});
assert.throws(() => zlib.crc32(null), {
code: 'ERR_INVALID_ARG_TYPE',
});
assert.throws(() => zlib.crc32({}), {
code: 'ERR_INVALID_ARG_TYPE',
});

if (common.isDebug) {
const { internalBinding } = require('internal/test/binding');
const { getV8FastApiCallCount } = internalBinding('debug');
assert.strictEqual(getV8FastApiCallCount('zlib.crc32'), 2);
assert.strictEqual(getV8FastApiCallCount('zlib.crc32.error'), 3);

Check failure on line 36 in test/sequential/test-zlib-crc32-fast-api.js

View workflow job for this annotation

GitHub Actions / x86_64-linux: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== 3 at Object.<anonymous> (/home/runner/work/_temp/node-v26.0.0-nightly2025-12-25efc5466e49-slim/test/sequential/test-zlib-crc32-fast-api.js:36:12) at Module._compile (node:internal/modules/cjs/loader:1803:14) at Object..js (node:internal/modules/cjs/loader:1934:10) at Module.load (node:internal/modules/cjs/loader:1524:32) at Module._load (node:internal/modules/cjs/loader:1326:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: 3, operator: 'strictEqual', diff: 'simple' } Node.js v26.0.0-pre Command: out/Release/node --expose-internals --no-warnings --allow-natives-syntax /home/runner/work/_temp/node-v26.0.0-nightly2025-12-25efc5466e49-slim/test/sequential/test-zlib-crc32-fast-api.js

Check failure on line 36 in test/sequential/test-zlib-crc32-fast-api.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== 3 at Object.<anonymous> (/home/runner/work/_temp/node-v26.0.0-nightly2025-12-25efc5466e49-slim/test/sequential/test-zlib-crc32-fast-api.js:36:12) at Module._compile (node:internal/modules/cjs/loader:1803:14) at Object..js (node:internal/modules/cjs/loader:1934:10) at Module.load (node:internal/modules/cjs/loader:1524:32) at Module._load (node:internal/modules/cjs/loader:1326:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: 3, operator: 'strictEqual', diff: 'simple' } Node.js v26.0.0-pre Command: out/Release/node --expose-internals --no-warnings --allow-natives-syntax /home/runner/work/_temp/node-v26.0.0-nightly2025-12-25efc5466e49-slim/test/sequential/test-zlib-crc32-fast-api.js
}
}
Loading