Skip to content

fix: binary file corruption#230

Merged
ryancyq merged 4 commits into
mainfrom
fix/binary-file-corruption
May 12, 2026
Merged

fix: binary file corruption#230
ryancyq merged 4 commits into
mainfrom
fix/binary-file-corruption

Conversation

@ryancyq
Copy link
Copy Markdown
Owner

@ryancyq ryancyq commented May 12, 2026

closes #210

Nr18 and others added 4 commits May 12, 2026 17:47
**Location:** `src/blob.ts`, line 28

The code was reading files with UTF-8 text encoding:
```typescript
fs.createReadStream(this.absolutePath, { encoding: 'utf8' })
```

Images are **binary files** containing arbitrary byte values (0-255). The UTF-8 encoding option tells Node.js to:
1. Interpret the binary data as UTF-8 text
2. Drop any byte sequences that are not valid UTF-8

This causes data loss because:
- Valid UTF-8 sequences are 1-4 bytes depending on the character
- Many byte combinations in binary files are invalid UTF-8 sequences
- These invalid bytes are silently dropped by the UTF-8 decoder
- The resulting file is corrupted (missing bytes)
The base64-encoder was converting base64 strings back to buffers before
pushing them to the stream, which caused them to be re-encoded as UTF-8
bytes. This corrupted binary files (images, PDFs, etc.) when they were
committed and pushed to GitHub.

Changes:
- base64-encoder.ts: Push base64 strings directly instead of converting
  them back to buffers. This prevents the double-encoding that was
  corrupting binary data.
- blob.ts: Remove UTF-8 encoding from file stream reading. Files are now
  read as raw buffers, which is necessary for the base64 encoder to work
  correctly with both text and binary files.

The fix ensures that:
- Binary files (PNG, JPG, PDF, etc.) are encoded without corruption
- Text files continue to work correctly
- The action properly base64 encodes file content for GitHub API

Fixes image corruption when committing and pushing images to GitHub
…ng a fixture with non-UTF-8 byte sequences to guard against silent data corruption
@ryancyq ryancyq force-pushed the fix/binary-file-corruption branch from 57bf0c9 to be96498 Compare May 12, 2026 10:03
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.31%. Comparing base (00de5a7) to head (be96498).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #230   +/-   ##
=======================================
  Coverage   97.31%   97.31%           
=======================================
  Files          11       11           
  Lines         261      261           
  Branches       59       59           
=======================================
  Hits          254      254           
  Misses          7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ryancyq ryancyq merged commit 1b72824 into main May 12, 2026
10 checks passed
@ryancyq ryancyq deleted the fix/binary-file-corruption branch May 12, 2026 10:08
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.

3 participants