src: fix crash on empty, foreign or truncated --snapshot-blob files - #65955
Open
codebytere wants to merge 1 commit into
Open
src: fix crash on empty, foreign or truncated --snapshot-blob files#65955codebytere wants to merge 1 commit into
codebytere wants to merge 1 commit into
Conversation
`node --snapshot-blob <file> main.js` aborted with an assertion when the file was empty (`ReadFileSync()` insists on reading one item), was not a Node.js snapshot (`CHECK_EQ(magic, kMagic)`) or had a zero-length startup blob, and read past the end of the buffer when a snapshot was truncated, because `BlobDeserializer` trusted every length field in the blob. `EmbedderSnapshotData::FromFile()` is documented to return an empty pointer for an invalid snapshot and crashed the same way. Bounds-check each read in `BlobDeserializer` and record the failure, have `SnapshotData::FromBlob()` print why and return false, and let `ReadFileSync()` return an empty vector for an empty file. Also add the missing space in the "built with Node.js version" messages. Refs: nodejs#38905 Refs: nodejs#47933 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
Collaborator
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65955 +/- ##
=======================================
Coverage 90.17% 90.17%
=======================================
Files 771 771
Lines 265489 265510 +21
Branches 50471 50477 +6
=======================================
+ Hits 239405 239432 +27
+ Misses 17042 17010 -32
- Partials 9042 9068 +26
🚀 New features to boost your workflow:
|
anonrig
approved these changes
Sep 10, 2026
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Collaborator
jasnell
approved these changes
Sep 11, 2026
Collaborator
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
node --snapshot-blob <file> main.jsaborts with an assertion when the file is empty, is not a Node.js snapshot, or has a zero-length startup blob, and reads past the end of the buffer when a snapshot is truncated, becauseBlobDeserializertrusted every length field in the blob;EmbedderSnapshotData::FromFile(), documented to return an empty pointer for an invalid snapshot, crashed the same way.BlobDeserializernow bounds-checks each read and records the failure,SnapshotData::FromBlob()prints "not a Node.js snapshot blob" or "truncated" and returns false so the CLI exits with the usual snapshot error code, andReadFileSync()accepts an empty file. Also adds the missing space in the "built with Node.js version" messages.Tests:
test/parallel/test-snapshot-invalid-blob.jscovers empty, garbage, zero-length-blob and truncated files (all aborted or overread before); the snapshot suites pass.Refs: #38905
Refs: #47933
Disclosure: the code, test and this description were written by Claude Code, directed and reviewed by @codebytere.