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