[PATCH] D35069: [Frontend] Verify that the bitstream is not empty before reading the serialised diagnostics

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 6 10:14:10 PDT 2017


arphaman created this revision.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D35069

Files:
  lib/Frontend/SerializedDiagnosticReader.cpp
  test/Index/Inputs/empty.dia
  test/Index/read-empty-diags.test


Index: test/Index/read-empty-diags.test
===================================================================
--- /dev/null
+++ test/Index/read-empty-diags.test
@@ -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
Index: lib/Frontend/SerializedDiagnosticReader.cpp
===================================================================
--- lib/Frontend/SerializedDiagnosticReader.cpp
+++ lib/Frontend/SerializedDiagnosticReader.cpp
@@ -27,6 +27,9 @@
   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' ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35069.105462.patch
Type: text/x-patch
Size: 837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170706/d17ec56c/attachment.bin>


More information about the cfe-commits mailing list