| Issue |
243552
|
| Summary |
[Object][XCOFF] XCOFFObjectFile::create overflows Base + symbol table offset before the bounds check; llvm-readobj crashes
|
| Labels |
crash,
llvm:binary-utilities
|
| Assignees |
|
| Reporter |
AnantaSrikar
|
`XCOFFObjectFile::create` reads the 64-bit symbol table offset from the file header and passes `Base + CurOffset` to `getObject`, which then checks that the range is inside the buffer. With a huge offset the pointer addition itself overflows, which is undefined behavior. UBSan reports it. Without sanitizers the check doesn't catch the wrapped pointer, and `llvm-readobj --file-headers` segfaults on a 24-byte file (main and Ubuntu 21.1.8; a 23.x release build crashes in `parseStringTable`, which `create` calls next).
**Version**: main at c7014922f582 (2026-11-16), built from the Git repository with `-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_USE_SANITIZER="Address;Undefined"`, on x86_64 Linux.
### Reproducer
```sh
# XCOFF64 file header: magic 0x01F7, 0 sections, symbol table offset
# 0xFFFFFF9888000000, 65536 symbols.
printf '\001\367\000\000\000\210\210\177\377\377\377\230\210\000\000\000\000\000\000\000\000\001\000\000' > xcoff64.o
llvm-readobj --file-headers xcoff64.o
```
With 0 symbols (the `\001` before the last two bytes changed to `\000`), it prints the header and exits 0.
### Observed
```
llvm/lib/Object/XCOFFObjectFile.cpp:1215:36: runtime error: addition of unsigned offset to 0x7ba3c85e01d0 overflowed to 0x7b3c505e01d0
#0 in llvm::object::XCOFFObjectFile::create(unsigned int, llvm::MemoryBufferRef) llvm/lib/Object/XCOFFObjectFile.cpp:1215:36
#1 in llvm::object::ObjectFile::createXCOFFObjectFile(llvm::MemoryBufferRef, unsigned int) llvm/lib/Object/XCOFFObjectFile.cpp:1238:10
#2 in llvm::object::ObjectFile::createObjectFile(llvm::MemoryBufferRef, llvm::file_magic, bool)
```
Without sanitizers: `Segmentation fault` (status 139).
### Expected
The existing `symbol table with offset 0x... and size 0x... goes past the end of the file` error.
### Analysis
https://github.com/llvm/llvm-project/blob/c7014922f5829426952a38d079220c21b0a8ebe8/llvm/lib/Object/XCOFFObjectFile.cpp#L1209-L1220
`getObject` and `Binary::checkOffset` only see the resulting pointer:
https://github.com/llvm/llvm-project/blob/c7014922f5829426952a38d079220c21b0a8ebe8/llvm/lib/Object/XCOFFObjectFile.cpp#L30-L39
Checking `CurOffset` and `SymbolTableSize` against `Data.getBufferSize()` as integers before forming the pointer would fix it.
This report was drafted with help from an AI assistant (Claude); I reviewed it and reproduced it myself.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs