Add safety check to extracting

This commit is contained in:
Pk11 2021-05-25 22:17:20 -05:00
commit f365f8710d

View file

@ -124,7 +124,17 @@ Result extractArchive(const std::string &archivePath, const std::string &wantedF
return EXTRACT_ERROR_ARCHIVE;
}
fwrite(buf, 1, size, file);
size_t written = fwrite(buf, 1, size, file);
/* Failed to write, likely out of space. */
if (written != size) {
fclose(file);
delete[] buf;
archive_read_close(a);
archive_read_free(a);
return EXTRACT_ERROR_WRITEFILE;
}
sizeLeft -= size;
writeOffset += size;
}