diff --git a/lib/Frontend/SerializedDiagnosticReader.cpp b/lib/Frontend/SerializedDiagnosticReader.cpp index 8a8161488f..08b7087fba 100644 --- a/lib/Frontend/SerializedDiagnosticReader.cpp +++ b/lib/Frontend/SerializedDiagnosticReader.cpp @@ -27,6 +27,9 @@ std::error_code SerializedDiagnosticReader::readDiagnostics(StringRef File) { llvm::BitstreamCursor Stream(**Buffer); Optional 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 index 0000000000..e69de29bb2 diff --git a/test/Index/read-empty-diags.test b/test/Index/read-empty-diags.test new file mode 100644 index 0000000000..cef751c920 --- /dev/null +++ b/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