Skip to content

Commit

Permalink
[Frontend] Verify that the bitstream is not empty before reading
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hyp committed Jul 7, 2017
1 parent ebbbc9c commit a43da82
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Frontend/SerializedDiagnosticReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand Down
Empty file added test/Index/Inputs/empty.dia
Empty file.
2 changes: 2 additions & 0 deletions test/Index/read-empty-diags.test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a43da82

Please sign in to comment.