THotPDF.DecodeBudgetBytes プロパティ

1つの 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;

ドキュメントインスタンスが少なくとも 1 つのフィルターをデコードするまで、このメソッドは False を返します

失敗時の動作

低レベルのデコードでは、いずれかのステージが合計バジェットを超えると EHPDFDecodeBudgetError が発生します。すでに False または nil で失敗を報告している高レベルの読み取りメソッドはその契約を維持し、理由は GetLastDecodeBudgetInfo で確認できます

DecodeBudgetBytes を 0 にするのは、チェーンごとの展開量を無制限にする必要がある信頼済みの入力に限ってください。負の値を指定すると 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