this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

parser: return early if ss3 contains an escape

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>

+35 -4
+35 -4
src/Parser.zig
··· 139 139 } 140 140 141 141 inline fn parseSs3(input: []const u8) Result { 142 - std.debug.assert(input.len >= 3); 142 + if (input.len < 3) { 143 + return .{ 144 + .event = null, 145 + .n = 0, 146 + }; 147 + } 143 148 const key: Key = switch (input[2]) { 149 + 0x1B => return .{ 150 + .event = null, 151 + .n = 2, 152 + }, 144 153 'A' => .{ .codepoint = Key.up }, 145 154 'B' => .{ .codepoint = Key.down }, 146 155 'C' => .{ .codepoint = Key.right }, ··· 167 176 } 168 177 169 178 inline fn parseApc(input: []const u8) Result { 170 - std.debug.assert(input.len >= 3); 179 + if (input.len < 3) { 180 + return .{ 181 + .event = null, 182 + .n = 0, 183 + }; 184 + } 171 185 const end = std.mem.indexOfScalarPos(u8, input, 2, 0x1b) orelse return .{ 172 186 .event = null, 173 187 .n = 0, ··· 188 202 189 203 /// Skips sequences until we see an ST (String Terminator, ESC \) 190 204 inline fn skipUntilST(input: []const u8) Result { 191 - std.debug.assert(input.len >= 3); 205 + if (input.len < 3) { 206 + return .{ 207 + .event = null, 208 + .n = 0, 209 + }; 210 + } 192 211 const end = std.mem.indexOfScalarPos(u8, input, 2, 0x1b) orelse return .{ 193 212 .event = null, 194 213 .n = 0, ··· 202 221 203 222 /// Parses an OSC sequence 204 223 inline fn parseOsc(input: []const u8, paste_allocator: ?std.mem.Allocator) !Result { 224 + if (input.len < 3) { 225 + return .{ 226 + .event = null, 227 + .n = 0, 228 + }; 229 + } 205 230 var bel_terminated: bool = false; 206 231 // end is the index of the terminating byte(s) (either the last byte of an 207 232 // ST or BEL) ··· 289 314 } 290 315 291 316 inline fn parseCsi(input: []const u8, text_buf: []u8) Result { 292 - // We start iterating at index 2 to get past te '[' 317 + if (input.len < 3) { 318 + return .{ 319 + .event = null, 320 + .n = 0, 321 + }; 322 + } 323 + // We start iterating at index 2 to get past the '[' 293 324 const sequence = for (input[2..], 2..) |b, i| { 294 325 switch (b) { 295 326 0x40...0xFF => break input[0 .. i + 1],