r307384 - [Frontend] Verify that the bitstream is not empty before reading
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 7 03:25:12 PDT 2017
Author: arphaman
Date: Fri Jul 7 03:25:12 2017
New Revision: 307384
URL: http://llvm.org/viewvc/llvm-project?rev=307384&view=rev
Log:
[Frontend] Verify that the bitstream is not empty before reading
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
Added:
cfe/trunk/test/Index/Inputs/empty.dia
cfe/trunk/test/Index/read-empty-diags.test
Modified:
cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp
Modified: cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp?rev=307384&r1=307383&r2=307384&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp (original)
+++ cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp Fri Jul 7 03:25:12 2017
@@ -27,6 +27,9 @@ std::error_code SerializedDiagnosticRead
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' ||
Added: cfe/trunk/test/Index/Inputs/empty.dia
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/empty.dia?rev=307384&view=auto
==============================================================================
(empty)
Added: cfe/trunk/test/Index/read-empty-diags.test
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/read-empty-diags.test?rev=307384&view=auto
==============================================================================
--- cfe/trunk/test/Index/read-empty-diags.test (added)
+++ cfe/trunk/test/Index/read-empty-diags.test Fri Jul 7 03:25:12 2017
@@ -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
More information about the cfe-commits
mailing list