[YAMLIO] Support non-null-terminated inputs
authorScott Linder <Scott.Linder@amd.com>
Mon, 16 Nov 2020 19:05:06 +0000 (19:05 +0000)
committerScott Linder <Scott.Linder@amd.com>
Wed, 18 Nov 2020 23:06:03 +0000 (23:06 +0000)
commit2980933d850b7506a1a96f8d11588b71956f4089
tree3eb3c3e84e334204526759f3ec0f148de962cdf0
parent544cb649d7789a4199e8acea6e8a9da1409702b1
[YAMLIO] Support non-null-terminated inputs

In some places the parser guards against dereferencing `End`, while in
others it relies on the presence of a trailing `'\0'` to elide checks.

Add the remaining guards needed to ensure the parser never attempts to
dereference `End`, making it safe to not require a null-terminated input
buffer.

Update the parser fuzzer harness so that it tests with buffers that are
guaranteed to be non-null-terminated, null-terminated, and 1-terminated,
additionally ensuring the result of the parse is the same in each case.

Some of the regression tests were written by inspection, and some are
cases caught by the fuzzer which required additional fixes in the
parser.

Differential Revision: https://reviews.llvm.org/D84050
llvm/lib/Support/YAMLParser.cpp
llvm/tools/llvm-yaml-parser-fuzzer/yaml-parser-fuzzer.cpp
llvm/unittests/Support/YAMLIOTest.cpp