]> granicus.if.org Git - clang/commitdiff
[Frontend] Verify that the bitstream is not empty before reading
authorAlex Lorenz <arphaman@gmail.com>
Fri, 7 Jul 2017 10:25:12 +0000 (10:25 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Fri, 7 Jul 2017 10:25:12 +0000 (10:25 +0000)
the serialised diagnostics

Clang should avoid calling report_fatal_error when the file with the serialised
diagnostics is empty. This commit changes Clang's serialised diagnostic reader,
now it reports an appropriate error instead of crashing.

rdar://31939877

Differential Revision: https://reviews.llvm.org/D35069

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307384 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/SerializedDiagnosticReader.cpp
test/Index/Inputs/empty.dia [new file with mode: 0644]
test/Index/read-empty-diags.test [new file with mode: 0644]

index 8a8161488f44796003d9b63fa11ad17e04d3e430..08b7087fbad62beb9c1a4bf92b3c754539aa50c7 100644 (file)
@@ -27,6 +27,9 @@ std::error_code SerializedDiagnosticReader::readDiagnostics(StringRef File) {
   llvm::BitstreamCursor Stream(**Buffer);
   Optional<llvm::BitstreamBlockInfo> BlockInfo;
 
+  if (Stream.AtEndOfStream())
+    return SDError::InvalidSignature;
+
   // Sniff for the signature.
   if (Stream.Read(8) != 'D' ||
       Stream.Read(8) != 'I' ||
diff --git a/test/Index/Inputs/empty.dia b/test/Index/Inputs/empty.dia
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Index/read-empty-diags.test b/test/Index/read-empty-diags.test
new file mode 100644 (file)
index 0000000..cef751c
--- /dev/null
@@ -0,0 +1,2 @@
+// RUN: not c-index-test -read-diagnostics %S/Inputs/empty.dia 2>&1 | FileCheck %s
+// CHECK: Trouble deserializing file (Invalid File): Invalid diagnostics signature