Skip to content

Commit

Permalink
[vrs} Relax limit on datalayout content blocks
Browse files Browse the repository at this point in the history
Summary: In D66209820, we introduced a sanity check on datalayout sizes to make our fuzzer happy. However, we do have incredibly large archives that go beyond these limits. This diff increases the tolerance for huge varsize datalaout sections to what can actually fit in a record.

Reviewed By: finik

Differential Revision: D66338418

fbshipit-source-id: 8426ba613957bd78dc78cb292ed3f43078e10939
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Nov 22, 2024
1 parent 1474631 commit e021ba5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions vrs/ContentBlockReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <logging/Log.h>
#include <logging/Verify.h>

#include <vrs/FileFormat.h>
#include <vrs/helpers/FileMacros.h>
#include <vrs/helpers/Throttler.h>
#include <vrs/os/CompilerAttributes.h>
Expand Down Expand Up @@ -439,19 +440,20 @@ bool DataLayoutBlockReader::readBlock(
// The size of the variable size buffer can be read from the var size index, so we read
// the fixed size buffer first, extract the size of the var size data from the var size index,
// so we can then read the var size buffer...
const size_t kMaxDataSize = 1024 * 1024 * 1024; // 1GB
const size_t kMaxFixedDataSize = 1024 * 1024 * 1024; // 1GB, arbitrary limit
const size_t kMaxRecordSize = 4 * 1024 * 1024 * 1024UL - sizeof(FileFormat::RecordHeader);
DataLayout& layout = *blockLayout_;
vector<int8_t>& fixedData = layout.getFixedData();
size_t fixedDataSize = layout.getFixedDataSizeNeeded();
if (!XR_VERIFY(fixedDataSize <= kMaxDataSize)) {
if (!XR_VERIFY(fixedDataSize <= kMaxFixedDataSize)) {
return false;
}
fixedData.resize(fixedDataSize);
vector<int8_t>& varData = layout.getVarData();
int readBlockStatus = record.reader->read(fixedData);
if (readBlockStatus == 0) {
size_t varDataSize = layout.getVarDataSizeFromIndex();
if (!XR_VERIFY(varDataSize <= kMaxDataSize)) {
if (!XR_VERIFY(fixedDataSize + varDataSize <= kMaxRecordSize)) {
return false;
}
varData.resize(varDataSize);
Expand Down

1 comment on commit e021ba5

@91391291151313
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.