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
彙總計算
每個通用篩選器在資料到達其支援記憶體串流之前,會先寫入有界的串流
- 如
[/ASCII85Decode /FlateDecode]的鏈會從一個共用預算耗用 ASCII85 輸出加上 Flate 輸出 - 支援的通用篩選器包含
FlateDecode、LZWDecode、ASCIIHexDecode、ASCII85Decode與RunLengthDecode,包含其 PDF 縮寫 - 影像預測器輸出與前置的通用影像篩選器共用相同的預算
- 原始編碼輸入不計入,因為預算衡量的是解碼所產生的展開量
- 每個獨立串流鏈都以全新的每鏈預算開始,而
DocumentDecodeBudgetBytes則提供獨立的文件層級上限
診斷
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);
}