87 const uint32_t nPages = m_pLinearized->GetPageCount();
91 const uint32_t nFirstPageNum = m_pLinearized->GetFirstPageNo();
92 if (nFirstPageNum >= nPages)
98 const uint32_t kHeaderSize = 288;
99 if (hStream->BitsRemaining() < kHeaderSize)
103 const uint32_t dwObjLeastNum = hStream
->GetBits(32
);
113 m_szFirstPageObjOffset = szFirstObjLoc;
117 const uint32_t dwDeltaObjectsBits = hStream
->GetBits(16
);
118 if (!IsValidPageOffsetHintTableBitCount(dwDeltaObjectsBits))
122 const uint32_t dwPageLeastLen = hStream
->GetBits(32
);
128 const uint32_t dwDeltaPageLenBits = hStream
->GetBits(16
);
129 if (!IsValidPageOffsetHintTableBitCount(dwDeltaPageLenBits))
133 hStream->SkipBits(96);
137 const uint32_t dwSharedObjBits = hStream
->GetBits(16
);
138 if (!IsValidPageOffsetHintTableBitCount(dwSharedObjBits))
143 const uint32_t dwSharedIdBits = hStream
->GetBits(16
);
144 if (!IsValidPageOffsetHintTableBitCount(dwSharedIdBits))
151 const uint32_t dwSharedNumeratorBits = hStream
->GetBits(16
);
152 if (dwSharedNumeratorBits > 32)
156 hStream->SkipBits(16);
158 FX_SAFE_UINT32 required_bits = dwDeltaObjectsBits;
159 required_bits *= nPages;
160 if (!CanReadFromBitStream(hStream, required_bits))
163 m_PageInfos = std::vector<PageInfo>(nPages);
164 m_PageInfos[nFirstPageNum].set_start_obj_num(
165 m_pLinearized->GetFirstPageObjNum());
167 FX_SAFE_UINT32 dwStartObjNum = 1;
168 for (uint32_t i = 0; i < nPages; ++i) {
169 FX_SAFE_UINT32 safeDeltaObj = hStream->GetBits(dwDeltaObjectsBits);
170 safeDeltaObj += dwObjLeastNum;
171 if (!safeDeltaObj.IsValid())
173 m_PageInfos[i].set_objects_count(safeDeltaObj.ValueOrDie());
174 if (i == nFirstPageNum)
176 m_PageInfos[i].set_start_obj_num(dwStartObjNum.ValueOrDie());
177 dwStartObjNum += m_PageInfos[i].objects_count();
178 if (!dwStartObjNum.IsValid() ||
185 required_bits = dwDeltaPageLenBits;
186 required_bits *= nPages;
187 if (!CanReadFromBitStream(hStream, required_bits))
190 for (uint32_t i = 0; i < nPages; ++i) {
191 FX_SAFE_UINT32 safePageLen = hStream->GetBits(dwDeltaPageLenBits);
192 safePageLen += dwPageLeastLen;
193 if (!safePageLen.IsValid())
195 m_PageInfos[i].set_page_length(safePageLen.ValueOrDie());
198 DCHECK(m_szFirstPageObjOffset);
199 m_PageInfos[nFirstPageNum].set_page_offset(m_szFirstPageObjOffset);
200 FX_FILESIZE prev_page_end = m_pLinearized->GetFirstPageEndOffset();
201 for (uint32_t i = 0; i < nPages; ++i) {
202 if (i == nFirstPageNum)
204 m_PageInfos[i].set_page_offset(prev_page_end);
205 prev_page_end += m_PageInfos[i].page_length();
210 required_bits = dwSharedObjBits;
211 required_bits *= nPages;
212 if (!CanReadFromBitStream(hStream, required_bits))
215 std::vector<uint32_t> dwNSharedObjsArray(nPages);
216 for (uint32_t i = 0; i < nPages; i++)
217 dwNSharedObjsArray[i] = hStream
->GetBits(dwSharedObjBits
);
221 for (uint32_t i = 0; i < nPages; i++) {
222 required_bits = dwSharedIdBits;
223 required_bits *= dwNSharedObjsArray[i];
224 if (!CanReadFromBitStream(hStream, required_bits))
227 for (uint32_t j = 0; j < dwNSharedObjsArray[i]; j++)
228 m_PageInfos[i].AddIdentifier(hStream->GetBits(dwSharedIdBits));
232 if (dwSharedNumeratorBits) {
233 for (uint32_t i = 0; i < nPages; i++) {
234 FX_SAFE_UINT32 safeSize = dwNSharedObjsArray[i];
235 safeSize *= dwSharedNumeratorBits;
236 if (!CanReadFromBitStream(hStream, safeSize))
239 hStream->SkipBits(safeSize.ValueOrDie());
244 FX_SAFE_UINT32 safeTotalPageLen = nPages;
245 safeTotalPageLen *= dwDeltaPageLenBits;
246 if (!CanReadFromBitStream(hStream, safeTotalPageLen))
249 hStream->SkipBits(safeTotalPageLen.ValueOrDie());
259 FX_SAFE_UINT32 bit_offset = offset;
261 if (!bit_offset.IsValid() || hStream->GetPos() > bit_offset.ValueOrDie())
263 hStream->SkipBits((bit_offset - hStream->GetPos()).ValueOrDie());
265 const uint32_t kHeaderSize = 192;
266 if (hStream->BitsRemaining() < kHeaderSize)
271 uint32_t dwFirstSharedObjNum = hStream
->GetBits(32
);
272 if (!dwFirstSharedObjNum)
278 if (!szFirstSharedObjLoc)
290 uint32_t dwSharedObjNumBits = hStream
->GetBits(16
);
291 if (dwSharedObjNumBits > 32)
303 if (!IsValidPageOffsetHintTableBitCount(dwDeltaGroupLen))
312 FX_SAFE_UINT32 required_bits = dwSharedObjTotal;
313 required_bits *= dwDeltaGroupLen;
314 if (!CanReadFromBitStream(hStream, required_bits))
317 if (dwSharedObjTotal > 0) {
318 uint32_t dwLastSharedObj = dwSharedObjTotal - 1;
319 if (dwLastSharedObj > m_nFirstPageSharedObjs) {
320 FX_SAFE_UINT32 safeObjNum = dwFirstSharedObjNum;
321 safeObjNum += dwLastSharedObj - m_nFirstPageSharedObjs;
322 if (!safeObjNum.IsValid())
327 m_SharedObjGroupInfos.resize(dwSharedObjTotal);
331 FX_SAFE_FILESIZE prev_shared_group_end_offset = m_szFirstPageObjOffset;
332 for (uint32_t i = 0; i < dwSharedObjTotal; ++i) {
333 if (i == m_nFirstPageSharedObjs)
334 prev_shared_group_end_offset = szFirstSharedObjLoc;
336 FX_SAFE_UINT32 safeObjLen = hStream->GetBits(dwDeltaGroupLen);
337 safeObjLen += dwGroupLeastLen;
338 if (!safeObjLen.IsValid())
341 m_SharedObjGroupInfos[i].m_dwLength = safeObjLen.ValueOrDie();
342 m_SharedObjGroupInfos[i].m_szOffset =
343 prev_shared_group_end_offset.ValueOrDie();
344 prev_shared_group_end_offset += m_SharedObjGroupInfos[i].m_dwLength;
345 if (!prev_shared_group_end_offset.IsValid())
353 uint32_t signature_count = 0;
354 for (uint32_t i = 0; i < dwSharedObjTotal; ++i) {
361 if (signature_count) {
362 required_bits = signature_count;
363 required_bits *= 128;
364 if (!CanReadFromBitStream(hStream, required_bits))
367 hStream->SkipBits(required_bits.ValueOrDie());
372 FX_SAFE_UINT32 cur_obj_num = m_pLinearized->GetFirstPageObjNum();
373 for (uint32_t i = 0; i < dwSharedObjTotal; ++i) {
374 if (i == m_nFirstPageSharedObjs)
375 cur_obj_num = dwFirstSharedObjNum;
377 FX_SAFE_UINT32 obj_count =
378 dwSharedObjNumBits ? hStream->GetBits(dwSharedObjNumBits) : 0;
380 if (!obj_count.IsValid())
383 uint32_t obj_num = cur_obj_num.ValueOrDie();
384 cur_obj_num += obj_count.ValueOrDie();
385 if (!cur_obj_num.IsValid())
388 m_SharedObjGroupInfos[i].m_dwStartObjNum = obj_num;
389 m_SharedObjGroupInfos[i].m_dwObjectsCount = obj_count.ValueOrDie();
410 if (index == m_pLinearized->GetFirstPageNo())
413 if (index >= m_pLinearized->GetPageCount())
416 const uint32_t dwLength = m_PageInfos[index].page_length();
420 if (!m_pValidator->CheckDataRangeAndRequestIfUnavailable(
421 m_PageInfos[index].page_offset(), dwLength)) {
426 for (
const uint32_t dwIndex : m_PageInfos[index].Identifiers()) {
427 if (dwIndex >= m_SharedObjGroupInfos.size())
429 const SharedObjGroupInfo& shared_group_info =
430 m_SharedObjGroupInfos[dwIndex];
432 if (!shared_group_info.m_szOffset || !shared_group_info.m_dwLength)
433 return CPDF_DataAvail::kDataError;
435 if (!m_pValidator->CheckDataRangeAndRequestIfUnavailable(
436 shared_group_info.m_szOffset, shared_group_info.m_dwLength)) {
437 return CPDF_DataAvail::kDataNotAvailable;
444 if (!pHintStream || !m_pLinearized->HasHintTable())
447 RetainPtr<
const CPDF_Dictionary> pDict = pHintStream->GetDict();
452 if (!pOffset || !pOffset->IsNumber())
455 int shared_hint_table_offset = pOffset->GetInteger();
456 if (shared_hint_table_offset <= 0)
460 pdfium::MakeRetain<CPDF_StreamAcc>(pdfium::WrapRetain(pHintStream));
461 pAcc->LoadAllDataFiltered();
463 uint32_t size = pAcc->GetSize();
467 const uint32_t kMinStreamLength = 60;
468 if (size < kMinStreamLength)
471 FX_SAFE_UINT32 safe_shared_hint_table_offset = shared_hint_table_offset;
472 if (!safe_shared_hint_table_offset.IsValid() ||
473 size < safe_shared_hint_table_offset.ValueOrDie()) {