From 74a41951e6b4957415868983ed24338256176457 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 8 Jun 2026 01:46:07 -0700 Subject: [PATCH] handle anchor events and fix another crash --- ...16058,execs:7921,op:arith8,pos:522,val:+10 | 31 +++++++++++++++++++ test.zig | 1 + yaml.zig | 9 ++++++ 3 files changed, 41 insertions(+) create mode 100644 fuzz/crashes/id:000000,sig:06,src:000000,time:16058,execs:7921,op:arith8,pos:522,val:+10 diff --git a/fuzz/crashes/id:000000,sig:06,src:000000,time:16058,execs:7921,op:arith8,pos:522,val:+10 b/fuzz/crashes/id:000000,sig:06,src:000000,time:16058,execs:7921,op:arith8,pos:522,val:+10 new file mode 100644 index 0000000000000000000000000000000000000000..09ca75df0d89db030be89209d8c35c457bcb1794 --- /dev/null +++ b/fuzz/crashes/id:000000,sig:06,src:000000,time:16058,execs:7921,op:arith8,pos:522,val:+10 @@ -0,0 +1,31 @@ +id: g982zq6e8wsvnmduerpbf8787hu85brugmngn8wf +name: yaml +main: yaml.zig +license: MIT +description: A Yaml parser built on top of libyaml +dependencies: + - src: git https://github.com/yaml/libyaml tag-0.2.5 + id: 8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc + license: MIT + c_include_dirs: + - include + c_source_flags: + - -DYAML_VERSION_MAJOR=0 + - -DYAML_VERSION_MINOR=2 + - -DYAML_VERSION_PATCH=5 + - -DYAML_VERSION_STRING="0.2.5" + - -DYAML_DECLARE_STATIC=1 + c_source_files: + *- src/api.c + - src/dumper.c + - src/emitter.c + - src/loader.c + - src/parser.c + - src/reader.c + - src/scanner.c + - src/writer.c + + - src: git https://github.com/nektro/zig-extras + +root_dependencies: + - src: git https://github.com/nektro/zig-expect diff --git a/test.zig b/test.zig index 048e03cc35ba2d75c068102f3478a0024df44a8e..d1f4d8bee7fdfe1cfc100671f32baeeb0aa329cc 100644 --- a/test.zig +++ b/test.zig @@ -24,6 +24,7 @@ test { fuzzCase(@embedFile("./fuzz/crashes/id:000000,sig:06,src:000000,time:6342 test { fuzzCase(@embedFile("./fuzz/crashes/id:000000,sig:06,src:000000,time:1310,execs:717,op:quick,pos:97")); } test { fuzzCase(@embedFile("./fuzz/crashes/id:000000,sig:06,src:000000,time:1399,execs:755,op:quick,pos:149")); } test { fuzzCase(@embedFile("./fuzz/crashes/id:000002,sig:06,src:000000,time:12249,execs:9637,op:int8,pos:0,val:+32")); } +test { fuzzCase(@embedFile("./fuzz/crashes/id:000000,sig:06,src:000000,time:16058,execs:7921,op:arith8,pos:522,val:+10")); } // zig fmt: on fn parseTest(comptime basename: [:0]const u8) !void { diff --git a/yaml.zig b/yaml.zig index d33ee6ef83e137855473c774cee1ad49c91d94bb..725fc3d19b2475d5eacdaa990720ed9b07d078f6 100644 --- a/yaml.zig +++ b/yaml.zig @@ -39,6 +39,7 @@ pub const Item = union(enum) { sequence: Sequence, string: [:0]const u8, stream: Stream, + anchor: [:0]const u8, pub fn deinit(self: *const Item, alloc: std.mem.Allocator) void { switch (self.*) { @@ -51,6 +52,7 @@ pub const Item = union(enum) { }, .string => |s| alloc.free(s), .stream => |s| s.deinit(alloc), + .anchor => {}, } } @@ -76,6 +78,9 @@ pub const Item = union(enum) { .string => { try writer.print("{s}", .{self.string}); }, + .anchor => { + // + }, } try writer.writeAll("}"); } @@ -97,6 +102,7 @@ pub const Value = union(enum) { string: [:0]const u8, mapping: Mapping, sequence: Sequence, + anchor: [:0]const u8, pub fn deinit(self: *const Value, alloc: std.mem.Allocator) void { switch (self.*) { @@ -108,6 +114,7 @@ pub const Value = union(enum) { for (s) |*item| item.deinit(alloc); alloc.free(s); }, + .anchor => {}, } } @@ -268,6 +275,7 @@ fn parse_item(p: *Parser, start: ?Token) Error!Item { c.YAML_MAPPING_START_EVENT => Item{ .mapping = try parse_mapping(p) }, c.YAML_SEQUENCE_START_EVENT => Item{ .sequence = try parse_sequence(p) }, c.YAML_SCALAR_EVENT => Item{ .string = try get_event_string(tok, p) }, + c.YAML_ALIAS_EVENT => .{ .anchor = std.mem.sliceTo(tok.data.alias.anchor, 0) }, else => unreachable, }; } @@ -344,6 +352,7 @@ fn parse_value(p: *Parser) Error!Value { .mapping => |x| Value{ .mapping = x }, .sequence => |x| Value{ .sequence = x }, .string => |x| Value{ .string = x }, + .anchor => |x| Value{ .anchor = x }, else => unreachable, }; } -- 2.54.0