THotPDF.DecodeBudgetBytes 屬性

設定單一 PDF 串流篩選器鏈中所有解碼階段可接受的彙總位元組數上限

宣告

// Delphi
property DecodeBudgetBytes: Int64;
function GetLastDecodeBudgetInfo(
  out AInfo: THPDFDecodeBudgetInfo): Boolean;

// C++Builder
__property __int64 DecodeBudgetBytes;
bool __fastcall GetLastDecodeBudgetInfo(
  THPDFDecodeBudgetInfo &AInfo);

預設值

268435456 個位元組,即 256 MiB

彙總計算

每個通用篩選器在資料到達其支援記憶體串流之前,會先寫入有界的串流

診斷

GetLastDecodeBudgetInfo 傳回最新的鏈限制、已接受的解碼位元組、最大階段、篩選器計數、限制狀態,以及超過限制的篩選器

THPDFDecodeBudgetInfo = record
  LimitBytes: Int64;
  DecodedBytes: Int64;
  PeakStageBytes: Int64;
  FilterCount: Integer;
  Exceeded: Boolean;
  ExceededFilter: AnsiString;
end;

在文件執行個體至少解碼過一個篩選器之前,此方法會傳回 False

失敗行為

當某個階段超過彙總預算時,低階解碼會引發 EHPDFDecodeBudgetError;已透過 False 或 nil 回報失敗的高階讀取方法會保留該合約,同時 GetLastDecodeBudgetInfo 會公開其原因

僅當需要無限每鏈展開的受信任輸入時,才將 DecodeBudgetBytes 設為零;負值會引發 ERangeError

Delphi 範例

PDF.DecodeBudgetBytes := 64 * 1024 * 1024;
if not PDF.ExtractEmbeddedFileBytes('payload.bin', Bytes) then
  if PDF.GetLastDecodeBudgetInfo(Info) and Info.Exceeded then
    Writeln('Decode limit reached in ', Info.ExceededFilter);

C++Builder 範例

pdf->DecodeBudgetBytes = 64LL * 1024 * 1024;
if (!pdf->ExtractEmbeddedFileBytes("payload.bin", bytes)) {
    THPDFDecodeBudgetInfo info;
    if (pdf->GetLastDecodeBudgetInfo(info) && info.Exceeded)
        ShowMessage("Decode limit reached in " + info.ExceededFilter);
}

相關 API