Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Fix set_data_len_bytes bounds check to prevent buffer overflow - #136

Merged
jgowdy-godaddy merged 7 commits into
mainfrom
fix-set-data-len-bounds-check
Mar 4, 2026
Merged

Fix set_data_len_bytes bounds check to prevent buffer overflow#136
jgowdy-godaddy merged 7 commits into
mainfrom
fix-set-data-len-bounds-check

Conversation

@jgowdy-godaddy

Copy link
Copy Markdown
Collaborator

Summary

  • Fix incorrect bounds check in CobhanBuffer::set_data_len_bytes that compared against raw allocation_size instead of the usable data region
  • The usable data region is allocation_size minus 24 bytes of overhead (8-byte header + 8-byte canary + 8-byte safety padding)
  • Without this fix, set_data_len_bytes would accept values up to 24 bytes larger than the actual data region, allowing writes past the canary into adjacent memory

Test plan

  • All 42 mocha tests pass
  • ESLint passes
  • Bun compatibility tests pass

jgowdy added 7 commits March 4, 2026 07:42
The check compared data_len_bytes against raw allocation_size, but the
usable data region is allocation_size minus 24 bytes of overhead (header,
canary, padding). Use AllocationSizeToMaxDataSize for the correct bound.
Compute AllocationSizeToMaxDataSize once in initialize() and store it
as max_data_size. Use the cached value in set_data_len_bytes() and for
the default data_len_bytes in initialize(). Also transfer it during
move operations.
- Check SetEnv return value and report errors to JavaScript
- Fix GetBooleanProperty to use defaultValue when property is
  undefined/null instead of coercing undefined to false
- Enable SensitiveCobhanBufferNapi secure wipe with is_valid() guard
  so moved-from objects skip the wipe; add deferred-read tests to
  verify async decrypt data survives event loop ticks and GC
- Skip verify_canaries on moved-from CobhanBuffer (cbuffer is null)
- Fall back to stderr in error_log when no log hook is configured
- Add set -e to integration-test.sh
- Add Promise<void> type parameter to setup_async and shutdown_async
…nters

- Validate SetMaxStackAllocItemSize rejects negative values instead of
  wrapping to a huge size_t that causes alloca stack overflow
- Remove duplicate system_name prefix in log hook messages; call_log_hook
  already prepends it so callers should not
- Null out all pointers in moved-from CobhanBuffer to prevent the
  destructor from dereferencing memory owned by the new object
- EndShutdownAsherah error message incorrectly said "EndSetupAsherah"
- RequireParameterBuffer error messages incorrectly said "Expected String"
- Change lint glob from src/**.ts to src/**/*.ts and test/**/*.ts
- Add test-specific eslint overrides for require imports and catch vars
- Add set -e to update-sums.sh, replace infinite retries with bounded
  retries and timeouts, quote URL variable
The string length was already measured to size the allocation. Derive
str_len from max_data_size instead of making a second N-API round-trip.
@jgowdy-godaddy
jgowdy-godaddy merged commit 5e54815 into main Mar 4, 2026
2 checks passed
@jgowdy-godaddy
jgowdy-godaddy deleted the fix-set-data-len-bounds-check branch March 4, 2026 16:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants