[clangd] Sanity-check array sizes read from disk before allocating them.
authorSam McCall <sam.mccall@gmail.com>
Wed, 11 Nov 2020 12:45:19 +0000 (13:45 +0100)
committerSam McCall <sam.mccall@gmail.com>
Wed, 11 Nov 2020 22:16:53 +0000 (23:16 +0100)
commit3c09103291686630564c1ff3f78c0f8dc69d069f
treeb7d803d1e27f598933e4b496dec5fbfe7c97bfe8
parent69ca17a92c20b3c01d55ea31331580625f37c168
[clangd] Sanity-check array sizes read from disk before allocating them.

Previously a corrupted index shard could cause us to resize arrays to an
arbitrary int32. This tends to be a huge number, and can render the
system unresponsive.

Instead, cap this at the amount of data that might reasonably be read
(e.g. the #bytes in the file). If the specified length is more than that,
assume the data is corrupt.

Differential Revision: https://reviews.llvm.org/D91258
clang-tools-extra/clangd/index/Serialization.cpp
clang-tools-extra/clangd/unittests/SerializationTests.cpp