Commit 9740b96
committed
fix: strip carriage returns and newlines from base64 attachment data
Fixes #494 - Windows attachment corruption bug
## Root Cause
Windows text-mode HTTP response processing converts embedded LF to CRLF in
base64 strings, resulting in double carriage returns (0d0d0a) in the decoded
binary output. Python's base64.urlsafe_b64decode() is strict and passes this
corrupted input through. Node.js implementations silently strip the corruption.
## Solution
Strip CR and LF from the base64 string before decoding. Per RFC 4648 Section 3.1,
base64 decoders should ignore embedded whitespace.
## Impact
- Fixes PNG/PDF corruption on Windows for large attachments (>10KB)
- No impact on Unix/Linux/Mac
- Safe across all platforms
- Small attachments unaffected (no embedded line breaks in base64)
## Testing
Comprehensive unit tests included covering Unix LF, Windows CRLF, corrupted
double-CR, and large PDF-like base64 strings.1 parent 519578c commit 9740b96
2 files changed
Lines changed: 61 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
887 | 888 | | |
888 | 889 | | |
889 | 890 | | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
894 | 895 | | |
895 | 896 | | |
896 | 897 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
0 commit comments