aboutsummaryrefslogtreecommitdiff
path: root/lib/std/json.zig
diff options
context:
space:
mode:
authorJon-Eric Cook <joneric.cook@gmail.com>2023-01-28 08:26:36 -0800
committerGitHub <noreply@github.com>2023-01-28 16:26:36 +0000
commit4c116841840bfa7f0068bef23984dd832da8a54d (patch)
treeeef882bbd8b87ab483b47b7e5b01951fab1a3c81 /lib/std/json.zig
parentf68d3c63df0486c7039732ef442c87fcd7c6fc57 (diff)
downloadzig-4c116841840bfa7f0068bef23984dd832da8a54d.tar.gz
zig-4c116841840bfa7f0068bef23984dd832da8a54d.zip
std.json: check output and source lengths in `std.json`
Diffstat (limited to 'lib/std/json.zig')
-rw-r--r--lib/std/json.zig3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/std/json.zig b/lib/std/json.zig
index f16d70da80..92afeead90 100644
--- a/lib/std/json.zig
+++ b/lib/std/json.zig
@@ -1384,7 +1384,7 @@ fn ParseInternalErrorImpl(comptime T: type, comptime inferred_types: []const typ
return errors;
},
.Array => |arrayInfo| {
- return error{ UnexpectedEndOfJson, UnexpectedToken } || TokenStream.Error ||
+ return error{ UnexpectedEndOfJson, UnexpectedToken, LengthMismatch } || TokenStream.Error ||
UnescapeValidStringError ||
ParseInternalErrorImpl(arrayInfo.child, inferred_types ++ [_]type{T});
},
@@ -1625,6 +1625,7 @@ fn parseInternal(
if (arrayInfo.child != u8) return error.UnexpectedToken;
var r: T = undefined;
const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
+ if (r.len != stringToken.decodedLength()) return error.LengthMismatch;
switch (stringToken.escapes) {
.None => mem.copy(u8, &r, source_slice),
.Some => try unescapeValidString(&r, source_slice),