[llvm] [gsymutil] Verify output string table size and address info offsets do not exceed 32-bit max (PR #181458)
Roy Shi via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 13 20:38:04 PST 2026
https://github.com/royitaqi created https://github.com/llvm/llvm-project/pull/181458
Previously, https://github.com/llvm/llvm-project/pull/165940 fixed llvm-dwarfdump and llvm-gsymutil so that they can correctly **consume** >4GB dSYM. However, if the dSYM is large enough, `llvm-gsymutil` can still **produce** invalid gSYM.
This change add validation into gsymutil, so that it will fail when the output string table or address info offsets will exceed 32-bit max.
Similar to https://github.com/llvm/llvm-project/pull/165940, it may be difficult to auto-test this change. For manual testing, I cannot find a large enough dSYM for which the gSYM would hit the limits (I have a 9GB dSYM which produces a 1.7GB gSYM). I'm open to ideas if anyone has any.
>From e4a66ab8c89593f313cd1532b4e17c6a2b2d31b3 Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Fri, 13 Feb 2026 20:28:04 -0800
Subject: [PATCH] Verify string table size and address info offsets
---
llvm/lib/DebugInfo/GSYM/GsymCreator.cpp | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
index d9df0e6f39d6c..f26e69fda2540 100644
--- a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
+++ b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
@@ -169,11 +169,25 @@ llvm::Error GsymCreator::encode(FileWriter &O) const {
const off_t StrtabSize = O.tell() - StrtabOffset;
std::vector<uint32_t> AddrInfoOffsets;
+ // Verify that the size of the string table does not exceed 32-bit max.
+ // This means the offsets in the string table will not exceed 32-bit max.
+ if (StrtabSize > UINT32_MAX) {
+ return createStringError(std::errc::invalid_argument,
+ "string table size exceeded 32-bit max");
+ }
+
// Write out the address infos for each function info.
for (const auto &FuncInfo : Funcs) {
- if (Expected<uint64_t> OffsetOrErr = FuncInfo.encode(O))
- AddrInfoOffsets.push_back(OffsetOrErr.get());
- else
+ if (Expected<uint64_t> OffsetOrErr = FuncInfo.encode(O)) {
+ // Verify that the address info offsets do not exceed 32-bit max.
+ uint64_t Offset = OffsetOrErr.get();
+ if (Offset > UINT32_MAX) {
+ return createStringError(std::errc::invalid_argument,
+ "address info offset exceeded 32-bit max");
+ }
+
+ AddrInfoOffsets.push_back(Offset);
+ } else
return OffsetOrErr.takeError();
}
// Fixup the string table offset and size in the header
More information about the llvm-commits
mailing list