5#include "core/fpdfapi/parser/cpdf_read_validator.h"
10#include "core/fpdfapi/parser/cpdf_stream.h"
11#include "core/fxcrt/fx_safe_types.h"
12#include "third_party/base/notreached.h"
19 return offset > 0 ? (offset - offset % kAlignBlockValue) : 0;
23 FX_SAFE_FILESIZE safe_result = AlignDown(offset);
24 safe_result += kAlignBlockValue;
25 return safe_result.ValueOrDefault(offset);
35 validator_->ResetErrors();
39 validator_->read_error_ |= saved_read_error_;
40 validator_->has_unavailable_data_ |= saved_has_unavailable_data_;
54 has_unavailable_data_ =
false;
64 FX_SAFE_FILESIZE end_offset = offset;
65 end_offset += buffer.size();
66 if (!end_offset.IsValid() || end_offset.ValueOrDie() > file_size_)
69 if (!IsDataRangeAvailable(offset, buffer.size())) {
70 ScheduleDownload(offset, buffer.size());
74 if (file_read_->ReadBlockAtOffset(buffer, offset))
78 ScheduleDownload(offset, buffer.size());
87 has_unavailable_data_ =
true;
88 if (!hints_ || size == 0)
91 const FX_FILESIZE start_segment_offset = AlignDown(offset);
92 FX_SAFE_FILESIZE end_segment_offset = offset;
93 end_segment_offset += size;
94 if (!end_segment_offset.IsValid()) {
99 std::min(file_size_, AlignUp(end_segment_offset.ValueOrDie()));
101 FX_SAFE_SIZE_T segment_size = end_segment_offset;
102 segment_size -= start_segment_offset;
103 if (!segment_size.IsValid()) {
107 hints_->AddSegment(start_segment_offset, segment_size.ValueOrDie());
112 return whole_file_already_available_ || !file_avail_ ||
113 file_avail_->IsDataAvail(offset, size);
117 const FX_SAFE_SIZE_T safe_size = file_size_;
118 whole_file_already_available_ =
119 whole_file_already_available_ ||
120 (safe_size.IsValid() && IsDataRangeAvailable(0, safe_size.ValueOrDie()));
122 return whole_file_already_available_;
128 if (offset > file_size_)
131 FX_SAFE_FILESIZE end_segment_offset = offset;
132 end_segment_offset += size;
135 if (!end_segment_offset.IsValid()) {
139 end_segment_offset =
std::min(
140 file_size_,
static_cast<
FX_FILESIZE>(end_segment_offset.ValueOrDie()));
141 FX_SAFE_SIZE_T segment_size = end_segment_offset;
142 segment_size -= offset;
143 if (!segment_size.IsValid()) {
148 if (IsDataRangeAvailable(offset, segment_size.ValueOrDie()))
151 ScheduleDownload(offset, segment_size.ValueOrDie());
159 const FX_SAFE_SIZE_T safe_size = file_size_;
160 if (safe_size.IsValid())
161 ScheduleDownload(0, safe_size.ValueOrDie());
ScopedSession(RetainPtr< CPDF_ReadValidator > validator)
CPDF_ReadValidator(RetainPtr< IFX_SeekableReadStream > file_read, CPDF_DataAvail::FileAvail *file_avail)
bool IsWholeFileAvailable()
FX_FILESIZE GetSize() override
bool CheckDataRangeAndRequestIfUnavailable(FX_FILESIZE offset, size_t size)
~CPDF_ReadValidator() override
bool ReadBlockAtOffset(pdfium::span< uint8_t > buffer, FX_FILESIZE offset) override
bool CheckWholeFileAndRequestIfUnavailable()
static constexpr int kFileBufSize