From 4d75ec97a4837fd6472b4dba1afcb2dd137e3622 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 8 Jun 2026 01:56:11 -0700 Subject: [PATCH] when splitting lines group consecutive \r\n and fix another crash --- ...:17906,execs:8822,op:arith8,pos:683,val:+3 | 30 +++++++++++++++++++ test.zig | 1 + yaml.zig | 6 ++++ 3 files changed, 37 insertions(+) create mode 100644 fuzz/crashes/id:000001,sig:06,src:000000,time:17906,execs:8822,op:arith8,pos:683,val:+3 diff --git a/fuzz/crashes/id:000001,sig:06,src:000000,time:17906,execs:8822,op:arith8,pos:683,val:+3 b/fuzz/crashes/id:000001,sig:06,src:000000,time:17906,execs:8822,op:arith8,pos:683,val:+3 new file mode 100644 index 0000000000000000000000000000000000000000..34a99462f7da955c25aea23353a0fa6e7267c01d --- /dev/null +++ b/fuzz/crashes/id:000001,sig:06,src:000000,time:17906,execs:8822,op:arith8,pos:683,val:+3 @@ -0,0 +1,30 @@ +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 d1f4d8bee7fdfe1cfc100671f32baeeb0aa329cc..888174967e3a04ee1bba2c9674992548d74a9aa7 100644 --- a/test.zig +++ b/test.zig @@ -25,6 +25,7 @@ test { fuzzCase(@embedFile("./fuzz/crashes/id:000000,sig:06,src:000000,time:1310 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")); } +test { fuzzCase(@embedFile("./fuzz/crashes/id:000001,sig:06,src:000000,time:17906,execs:8822,op:arith8,pos:683,val:+3")); } // zig fmt: on fn parseTest(comptime basename: [:0]const u8) !void { diff --git a/yaml.zig b/yaml.zig index 725fc3d19b2475d5eacdaa990720ed9b07d078f6..c93ab810d3d4f192ce9ca7c09e00bcb9119aa4e0 100644 --- a/yaml.zig +++ b/yaml.zig @@ -408,6 +408,12 @@ fn split(alloc: std.mem.Allocator, in: string) ![]string { var iter = std.mem.splitAny(u8, in, "\r\n"); while (iter.next()) |str| { + if (str.len == 0) { + if ((str.ptr - 1)[0] == '\r' and str.ptr[0] == '\n') { + try list.append(iter.next() orelse break); + continue; + } + } try list.append(str); } return try list.toOwnedSlice(); -- 2.54.0