Skip to content

Conversation

@Nr18
Copy link

@Nr18 Nr18 commented Feb 12, 2026

Overview

This PR fixes a critical issue where binary files (images, PDFs, etc.) were being corrupted when committed and pushed to GitHub through this action. The root cause was improper handling of file encoding in both the file reading and base64 encoding streams.

Problem Statement

When users committed image files (PNG, JPG, etc.) using this action, the images would become corrupted and unable to open after being pushed to the repository. This was caused by two issues:

  1. File Reading: Files were being read with UTF-8 text encoding, which drops invalid UTF-8 byte sequences. Binary files contain arbitrary byte values that aren't valid UTF-8, resulting in data loss.

  2. Base64 Encoding: The Base64Encoder was converting base64 strings back to Buffers before pushing them to the stream, causing double-encoding that further corrupted the data.

Root Cause Analysis

  • src/blob.ts (line 28): Used encoding: 'utf8' in createReadStream(), which corrupted binary data
  • src/stream/base64-encoder.ts: Called Buffer.from(base64String) which re-encoded the base64 string as UTF-8 bytes, breaking the encoded content

Changes Made

1. src/blob.ts

  • Removed: UTF-8 encoding parameter from fs.createReadStream()
  • Effect: Files are now read as raw buffers for both text and binary files
  • Benefit: Preserves the exact binary content without any data loss

2. src/stream/base64-encoder.ts

  • Changed: Push base64 strings directly to the stream instead of converting them back to buffers
  • Before: this.push(Buffer.from(base64String))
  • After: this.push(base64String)
  • Benefit: Prevents double-encoding and data corruption

Testing

  • ✅ All 61 existing tests pass
  • ✅ Text files continue to work correctly
  • ✅ Binary files are now properly encoded without corruption
  • ✅ Build verified with npm run build - dist folder updated

Impact

  • Fixes: Image corruption when committing PNG, JPG, and other binary files
  • Maintains: Backward compatibility with text file commits
  • Improves: Reliability of the action for all file types

Files Changed

  • src/blob.ts
  • src/stream/base64-encoder.ts
  • dist/index.js (bundled)

Related Issues

Closes the image corruption issue when using this action to commit binary files

Nr18 added 2 commits February 12, 2026 09:30
**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
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.

1 participant