From 92e1c71dd6c43e28c2e0a2ffbcb7262363ed5c6b Mon Sep 17 00:00:00 2001 From: Tetralux Date: Fri, 28 Feb 2020 14:52:16 +0000 Subject: [PATCH] Fix encoding/base64 encoding null bytes incorrectly Fixes #574. Thanks @jroatch! --- core/encoding/base64/base64.odin | 10 +++++----- 1 file 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 +}