Skip to content

Commit 068d5ee

Browse files
leveldb Teama-sully
authored andcommitted
leveldb: Check slice length in Footer::DecodeFrom()
Without this check decoding the footer in Table::Open() can read uninitialized bytes from a buffer allocated on the stack if the file was unexpectedly short. In practice this is probably fine since this function validates a magic number but MSan complains about branching on uninitialized data. PiperOrigin-RevId: 525271012
1 parent c61238d commit 068d5ee

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

table/format.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ void Footer::EncodeTo(std::string* dst) const {
4141
}
4242

4343
Status Footer::DecodeFrom(Slice* input) {
44+
if (input->size() < kEncodedLength) {
45+
return Status::Corruption("not an sstable (footer too short)");
46+
}
47+
4448
const char* magic_ptr = input->data() + kEncodedLength - 8;
4549
const uint32_t magic_lo = DecodeFixed32(magic_ptr);
4650
const uint32_t magic_hi = DecodeFixed32(magic_ptr + 4);

0 commit comments

Comments
 (0)