Validate source text size and fix empty buffer bugs. (#1113)

There's currently a bug with empty files, in that it initializes SourceBuffer with an invalid StringRef that results in a crash. That got me looking at the std::optional TODO, but the issue is that there are really three states:

- Buffered
- mmapped (not buffered)
- Moved out of (no longer initialized)

Technically an optional could work if we initialize the buffer on move out, indicating the mmap is gone. But the mode setup felt better to me.

And then this also adds the size check. Which is really how I started looking at this.
This commit is contained in:
Jon Meow
2022-03-02 13:43:03 -08:00
committed by GitHub
parent 18b423dc5f
commit 8a2ef22c2a
8 changed files with 99 additions and 69 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data,
llvm::StringRef(reinterpret_cast<const char*>(data), size));
// Lex the input.
auto tokens = TokenizedBuffer::Lex(source, NullDiagnosticConsumer());
auto tokens = TokenizedBuffer::Lex(*source, NullDiagnosticConsumer());
if (tokens.HasErrors()) {
return 0;
}