[PATCH] D95554: [BitcodeReader] Validate Strtab before accessing.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 22 06:48:00 PDT 2021


fhahn updated this revision to Diff 353632.
fhahn added a comment.

rebased, I'm planning on landing this soon.

In D95554#2531446 <https://reviews.llvm.org/D95554#2531446>, @pcc wrote:

> I think there are more of these, search for `Strtab.data()` in that file.

Yes, those probably should also be audited. But I am not sure how to best get test cases for those. I'll take a look at some other oss-fuzz bugs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95554/new/

https://reviews.llvm.org/D95554

Files:
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/test/Bitcode/invalid-record-strtab.ll
  llvm/test/Bitcode/invalid-record-strtab.ll.bc


Index: llvm/test/Bitcode/invalid-record-strtab.ll
===================================================================
--- /dev/null
+++ llvm/test/Bitcode/invalid-record-strtab.ll
@@ -0,0 +1,5 @@
+; Bitcode with an invalid record that indexes a name outside of strtab.
+
+; RUN: not llvm-dis %s.bc -o - 2>&1 | FileCheck %s
+
+; CHECK: error: Invalid record
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===================================================================
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3407,9 +3407,12 @@
 
   // Record[16] is the address space number.
 
-  // Check whether we have enough values to read a partition name.
-  if (Record.size() > 18)
+  // Check whether we have enough values to read a partition name. Also make
+  // sure Strtab has enough values.
+  if (Record.size() > 18 && Strtab.data() &&
+      Record[17] + Record[18] <= Strtab.size()) {
     Func->setPartition(StringRef(Strtab.data() + Record[17], Record[18]));
+  }
 
   ValueList.push_back(Func);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95554.353632.patch
Type: text/x-patch
Size: 1060 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210622/0e1bd78c/attachment.bin>


More information about the llvm-commits mailing list