Bug 733977 - Check more closely for corrupt sessionHistogram files. r=taras

This commit is contained in:
Nathan Froyd 2012-03-08 13:05:40 -05:00
Родитель d18fcfcbe9
Коммит be6fbf5557
1 изменённых файлов: 10 добавлений и 1 удалений

Просмотреть файл

@ -1128,8 +1128,10 @@ TelemetrySessionData::LoadFromDisk(nsIFile *file, TelemetrySessionData **ptr)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
// If there's not even enough data to read the header for the pickle,
// don't bother. Conveniently, this handles the error case as well.
PRInt32 size = PR_Available(fd); PRInt32 size = PR_Available(fd);
if (size == -1) { if (size < static_cast<PRInt32>(sizeof(Pickle::Header))) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -1142,6 +1144,13 @@ TelemetrySessionData::LoadFromDisk(nsIFile *file, TelemetrySessionData **ptr)
Pickle pickle(data, size); Pickle pickle(data, size);
void *iter = NULL; void *iter = NULL;
// Make sure that how much data the pickle thinks it has corresponds
// with how much data we actually read.
const Pickle::Header *header = pickle.headerT<Pickle::Header>();
if (header->payload_size != static_cast<PRUint32>(amount) - sizeof(*header)) {
return NS_ERROR_FAILURE;
}
unsigned int storedVersion; unsigned int storedVersion;
if (!(pickle.ReadUInt32(&iter, &storedVersion) if (!(pickle.ReadUInt32(&iter, &storedVersion)
&& storedVersion == sVersion)) { && storedVersion == sVersion)) {