Skip to content

Commit 13831b4

Browse files
committed
Prevent auto normalise line endings for pdf documents
1 parent 0d56b9a commit 13831b4

8 files changed

Lines changed: 19 additions & 0 deletions

File tree

.gitattributes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
###############################################################################
44
* text=auto
55

6+
###############################################################################
7+
# Binary test assets must never be line-ending normalized.
8+
#
9+
# Some test PDFs are fully uncompressed (no NUL bytes), so git's text=auto
10+
# heuristic misdetects them as text and strips CR bytes when storing the blob.
11+
# That corrupts the binary xref byte offsets, so the file checks out broken on
12+
# platforms that use LF (Linux/macOS) while Windows autocrlf masks the issue.
13+
# Forcing these as binary keeps the bytes identical on every platform.
14+
###############################################################################
15+
*.pdf binary
16+
*.png binary
17+
*.jpg binary
18+
*.jpeg binary
19+
*.gif binary
20+
*.ico binary
21+
*.snk binary
22+
623
###############################################################################
724
# Set default behavior for command prompt diff.
825
#

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ dotnet test --filter "FullyQualifiedName~ClassName.MethodName" UglyToad.PdfPig.R
2323

2424
Test framework: **xUnit**. Test PDFs live in `UglyToad.PdfPig.Rendering.Skia.Tests/Documents/`.
2525

26+
> **Binary test assets must stay binary in git.** `.gitattributes` has `* text=auto`, but uncompressed PDFs contain no NUL bytes, so git's heuristic misdetects them as *text* and strips CR bytes on storage. A PDF's xref uses absolute byte offsets, so dropping CRs shifts the layout and breaks them: the file checks out fine on Windows (`autocrlf` restores CRLF) but corrupt on Linux/macOS (LF), giving `IndexOutOfRangeException` in `MemoryInputBytes.Seek` / `PdfTokenScanner.TryReadStream`. The bug is byte-based, not OS-based — feeding the LF blob to the renderer fails on any OS. `.gitattributes` therefore force-marks `*.pdf` (and `*.png/jpg/jpeg/gif/ico/snk`) as `binary`. After adding a new test PDF, confirm `git check-attr -a <file>` reports `binary: set`; if it was committed before the rule, run `git add --renormalize .`.
27+
2628
#### Image-regression tests (`PdfPigSkiaTest`)
2729

2830
The bulk of the suite renders a PDF page and compares it pixel-by-pixel against a committed golden PNG. Things to know before touching the renderer:
147 Bytes
Binary file not shown.
Binary file not shown.
139 Bytes
Binary file not shown.
87 Bytes
Binary file not shown.
11 Bytes
Binary file not shown.
85 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)