[PATCH] D127369: [Object][COFF] Fix section name parsing error when the name field is not null-padded
Pengxuan Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 9 10:43:21 PDT 2022
pzheng updated this revision to Diff 435610.
pzheng added a comment.
Update the test to address @mstorsjo's comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127369/new/
https://reviews.llvm.org/D127369
Files:
llvm/lib/Object/COFFObjectFile.cpp
llvm/test/tools/llvm-objdump/COFF/Inputs/long-section-name.yaml
llvm/test/tools/llvm-objdump/COFF/long-section-name.test
Index: llvm/test/tools/llvm-objdump/COFF/long-section-name.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/COFF/long-section-name.test
@@ -0,0 +1,30 @@
+# RUN: yaml2obj %S/Inputs/long-section-name.yaml -o %t.obj
+
+## Replace the section name field of the object file with /4\0abcde emulating
+## a section name field not fully null-padded at the end.
+# RUN: %python %s %t.obj
+
+## This should print the LongSectionName section.
+# RUN: llvm-objdump --headers %t.obj | FileCheck %s
+
+# CHECK: LongSectionName
+
+import sys
+
+if len(sys.argv) < 2:
+ print("Use: python3 long-section-name.test <OBJECT_FILE>")
+ exit(1)
+
+template = bytes('/4', 'utf-8')
+replacement = b'/4\0abcde'
+
+data = None
+with open(sys.argv[1], "rb") as inp:
+ data = inp.read()
+with open(sys.argv[1], "wb") as outp:
+ pos = data.find(template)
+ if pos == -1:
+ sys.exit("Error: Pattern /4 not found in " + sys.argv[1])
+ outp.write(data[:pos])
+ outp.write(replacement)
+ outp.write(data[pos + len(replacement):])
Index: llvm/test/tools/llvm-objdump/COFF/Inputs/long-section-name.yaml
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/COFF/Inputs/long-section-name.yaml
@@ -0,0 +1,15 @@
+--- !COFF
+header:
+ Machine: IMAGE_FILE_MACHINE_ARM64
+ Characteristics: [ ]
+sections:
+ - Name: LongSectionName
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+symbols:
+ - Name: LongSectionName
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+...
Index: llvm/lib/Object/COFFObjectFile.cpp
===================================================================
--- llvm/lib/Object/COFFObjectFile.cpp
+++ llvm/lib/Object/COFFObjectFile.cpp
@@ -1168,7 +1168,7 @@
return createStringError(object_error::parse_failed,
"invalid section name");
} else {
- if (Name.substr(1).getAsInteger(10, Offset))
+ if (Name.substr(1).consumeInteger(10, Offset))
return createStringError(object_error::parse_failed,
"invalid section name");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127369.435610.patch
Type: text/x-patch
Size: 2354 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220609/f53eb7e6/attachment.bin>
More information about the llvm-commits
mailing list