Commit b31a3cd
committed
fix: Add bounds checks in reflection API to prevent memory corruption
Add bounds checks to prevent out-of-bounds memory access when processing
malformed binary schema (.bfbs) files through the reflection API.
Changes:
- src/reflection.cpp ForAllFields(): Add bounds check before using
field->id() as array index. field->id() is a uint16_t (range 0-65535)
but the array is sized to fields()->size(). A malformed schema with
id >= fields()->size() would cause heap OOB write.
- src/reflection.cpp VerifyObject(): Add minimum offset check for union
fields before subtraction. field->offset() - sizeof(voffset_t) underflows
when offset < 2, causing OOB read at offset 0xFFFF/0xFFFE from table pointer.
- src/bfbs_gen.h FieldIdToIndex(): Same bounds check as ForAllFields() -
both functions have identical vulnerable pattern.
These checks add minimal overhead and protect against malformed schema files
without breaking valid use cases. All existing tests pass.1 parent 38df293 commit b31a3cd
2 files changed
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
253 | 257 | | |
254 | 258 | | |
255 | 259 | | |
| |||
384 | 388 | | |
385 | 389 | | |
386 | 390 | | |
387 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
388 | 396 | | |
389 | 397 | | |
390 | 398 | | |
| |||
0 commit comments