Skip to content

fix: compute integrity over transformed bytes when a transform is applied#450

Merged
VerteDinde merged 1 commit into
mainfrom
fix/transform-integrity-277
Jun 28, 2026
Merged

fix: compute integrity over transformed bytes when a transform is applied#450
VerteDinde merged 1 commit into
mainfrom
fix/transform-integrity-277

Conversation

@claude

@claude claude Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Requested by Samuel Attard · Slack thread

Fixes #277.

Before

When a transform is registered, the transformed content is written to a temporary file and that temp file's bytes are what actually get stored in the archive. The file's size is also taken from the transformed temp file. However, the integrity hash was still computed from the original, pre-transform source stream (getFileIntegrity(streamGenerator())).

As a result, the header's integrity hash (and block hashes) did not match the bytes that were actually stored in the archive. Any consumer that validates the stored content against the recorded integrity would see a mismatch whenever a transform changed the bytes.

After

The integrity is computed over the transformed temp file, so the recorded hash and blocks match the bytes that are actually stored in the archive.

How

In src/filesystem.ts, insertFileAsync now hashes the transformed output instead of re-reading the untransformed source:

-    node.integrity = await getFileIntegrity(streamGenerator());
+    node.integrity = await getFileIntegrity(fs.createReadStream(file.transformed.path));

This mirrors what disk.ts already does when writing the archive body, which reads from transformed.path for transformed files.

A regression test was added (test/asar-spec.ts, under the transform describe block) that packs a file with a byte-changing transform and asserts that the header integrity matches the SHA256 of the actual stored (transformed) bytes returned by extractFile. This test fails without the fix and passes with it.

The test/expected/packthis-transformed.asar fixture was regenerated; the only change is file0.txt's integrity hash, which now reflects the stored (transformed) bytes instead of the original ones — the rest of the header is byte-identical.

Testing

  • New regression test fails before the fix, passes after.
  • Full Node test suite passes (188 tests). The Electron-runner pass of yarn test was not exercised in this environment because the Electron binary download is blocked here; it runs the same test files unchanged.

Generated by Claude Code

…lied

When a transform is registered, the transformed content is written to a
temporary file and stored in the archive, but the integrity hash was still
computed from the original (pre-transform) source stream. This meant the
header integrity did not match the bytes actually stored in the archive.

Compute the integrity over the transformed temp file so the recorded hash
and block hashes match the stored bytes.

The packthis-transformed expected fixture has been regenerated; the only
change is file0.txt's integrity hash, which now reflects the stored
(transformed) bytes instead of the original ones.

Fixes #277
@MarshallOfSound MarshallOfSound marked this pull request as ready for review June 27, 2026 21:47
@MarshallOfSound MarshallOfSound requested a review from a team as a code owner June 27, 2026 21:47
@VerteDinde VerteDinde merged commit 8c9be01 into main Jun 28, 2026
9 checks passed
@VerteDinde VerteDinde deleted the fix/transform-integrity-277 branch June 28, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect integrity of transformed files?

3 participants