Commit d3d3893
committed
fix(c): two CRITICAL memory bugs in standalone C (ASan/test-confirmed)
1. read_file() called realloc() directly on buf.data, which may point at the
4096-byte stack buffer (buffer_init uses stack storage when capacity<=4096).
A file of exactly STACK_BUFFER_SIZE bytes -> realloc of a stack pointer ->
heap corruption/crash. Now uses buffer_append(), which routes through
buffer_grow() and correctly migrates stack->heap.
2. make_utf8() memcpy'd strlen(token) into a fixed uint8_t[4]; a runtime map
(PRINTABLE_BINARY_MAP) with a >4-byte glyph token overflowed the stack.
make_utf8 now clamps to MAX_UTF8_BYTES and load_map_from_path rejects
over-long glyph tokens with a clear error.
Also: encode_data() was missing buffer_prepare_return() that every sibling
returner has (latent dangling-stack-return, masked only by INITIAL_BUFFER_SIZE
> STACK_BUFFER_SIZE); added for correctness/consistency.
Tests: test/test #5b (4095/4096/4097/8192-byte boundary roundtrip) and #5c
(malformed runtime map rejected, not crashed). Both RED before, GREEN after;
cross-impl-safe (Lua/Zig/C all pass).1 parent 95aba31 commit d3d3893
2 files changed
Lines changed: 54 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
276 | | - | |
277 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
278 | 280 | | |
279 | 281 | | |
280 | 282 | | |
| |||
343 | 345 | | |
344 | 346 | | |
345 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
346 | 355 | | |
347 | 356 | | |
348 | 357 | | |
| |||
952 | 961 | | |
953 | 962 | | |
954 | 963 | | |
| 964 | + | |
955 | 965 | | |
956 | 966 | | |
957 | 967 | | |
| |||
1115 | 1125 | | |
1116 | 1126 | | |
1117 | 1127 | | |
1118 | | - | |
1119 | | - | |
1120 | | - | |
1121 | | - | |
1122 | | - | |
1123 | | - | |
1124 | | - | |
1125 | | - | |
1126 | | - | |
1127 | | - | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
1128 | 1134 | | |
1129 | 1135 | | |
1130 | 1136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
220 | 256 | | |
221 | 257 | | |
222 | 258 | | |
| |||
0 commit comments