diff options
| author | Tetralux <tetralux@teknik.io> | 2020-02-28 14:52:16 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-28 14:52:16 +0000 |
| commit | 92e1c71dd6c43e28c2e0a2ffbcb7262363ed5c6b (patch) | |
| tree | f37b073fed6d0d598573d029f3e6c5bb41b55ede /core/encoding | |
| parent | 3d74c2f6c0797345c2bdfae77c619057227e8181 (diff) | |
Fix encoding/base64 encoding null bytes incorrectly
Fixes #574.
Thanks @jroatch!
Diffstat (limited to 'core/encoding')
| -rw-r--r-- | core/encoding/base64/base64.odin | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/core/encoding/base64/base64.odin b/core/encoding/base64/base64.odin index 0224e93e4..2724aa0e5 100644 --- a/core/encoding/base64/base64.odin +++ b/core/encoding/base64/base64.odin @@ -49,7 +49,7 @@ encode :: proc(data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocato c0, c1, c2, block: int; for i, d := 0, 0; i < length; i, d = i + 3, d + 4 { - c0, c1, c2 = int(data[i]), 0, 0; + c0, c1, c2 = int(data[i]), -1, -1; if i + 1 < length do c1 = int(data[i + 1]); if i + 2 < length do c2 = int(data[i + 2]); @@ -58,13 +58,13 @@ encode :: proc(data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocato out[d] = ENC_TBL[block >> 18 & 63]; out[d + 1] = ENC_TBL[block >> 12 & 63]; - out[d + 2] = c1 == 0 ? PADDING : ENC_TBL[block >> 6 & 63]; - out[d + 3] = c2 == 0 ? PADDING : ENC_TBL[block & 63]; + out[d + 2] = c1 == -1 ? PADDING : ENC_TBL[block >> 6 & 63]; + out[d + 3] = c2 == -1 ? PADDING : ENC_TBL[block & 63]; } return string(out); } -decode :: proc(data: string, DEC_TBL := DEC_TABLE, allocator := context.allocator) -> []byte #no_bounds_check{ +decode :: proc(data: string, DEC_TBL := DEC_TABLE, allocator := context.allocator) -> []byte #no_bounds_check { length := len(data); if length == 0 do return []byte{}; @@ -90,4 +90,4 @@ decode :: proc(data: string, DEC_TBL := DEC_TABLE, allocator := context.allocato out[j + 2] = byte(b2); } return out; -}
\ No newline at end of file +} |