From 5ff6b8655a3f7b0b23dba272a3dc0c9add82897b Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 7 Jul 2017 10:25:12 +0000 Subject: [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 llvm-svn: 307384 --- clang/lib/Frontend/SerializedDiagnosticReader.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clang/lib/Frontend/SerializedDiagnosticReader.cpp') diff --git a/clang/lib/Frontend/SerializedDiagnosticReader.cpp b/clang/lib/Frontend/SerializedDiagnosticReader.cpp index 8a8161488f4..08b7087fbad 100644 --- a/clang/lib/Frontend/SerializedDiagnosticReader.cpp +++ b/clang/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' || -- cgit v1.2.3