status_t Init(const BPackageData& data) { fOffset = data.Offset(); fCompressedSize = data.CompressedSize(); fUncompressedSize = data.UncompressedSize(); fChunkSize = data.ChunkSize(); // validate chunk size if (fChunkSize == 0) fChunkSize = B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB; if (fChunkSize < kMinSaneZlibChunkSize || fChunkSize > kMaxSaneZlibChunkSize) { return B_BAD_DATA; } fChunkCount = (fUncompressedSize + (fChunkSize - 1)) / fChunkSize; fOffsetTableSize = (fChunkCount - 1) * sizeof(uint64); if (fOffsetTableSize >= fCompressedSize) return B_BAD_DATA; // allocate a buffer for the offset table if (fChunkCount > 1) { fOffsetTableBufferEntryCount = std::min(fChunkCount - 1, (uint64)kMaxZlibOffsetTableBufferSize); fOffsetTable = new(std::nothrow) uint64[ fOffsetTableBufferEntryCount]; if (fOffsetTable == NULL) return B_NO_MEMORY; fOffsetTableIndex = -1; // mark the table content invalid } else fChunkSize = fUncompressedSize; // mark uncompressed content invalid fUncompressedChunk = -1; return B_OK; }
status_t Init(const BPackageData& data) { fOffset = data.Offset(); fSize = data.UncompressedSize(); return B_OK; }