Fix CID 1164693 (Untrusted value as argument)

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2018-07-06 15:13:13 +02:00
parent 992031e824
commit 4bb41b8952

View File

@ -50,10 +50,12 @@ bool IndexMap::Serialize(FILE* fp) const {
// Reads from the given file. Returns false in case of error.
// If swap is true, assumes a big/little-endian swap is needed.
bool IndexMap::DeSerialize(bool swap, FILE* fp) {
int32_t sparse_size;
uint32_t sparse_size;
if (fread(&sparse_size, sizeof(sparse_size), 1, fp) != 1) return false;
if (swap)
ReverseN(&sparse_size, sizeof(sparse_size));
// Arbitrarily limit the number of elements to protect against bad data.
if (sparse_size > UINT16_MAX) return false;
sparse_size_ = sparse_size;
if (!compact_map_.DeSerialize(swap, fp)) return false;
return true;