THotPDF.DecodeBudgetBytes Property
Sets the maximum aggregate number of bytes accepted from all decoding stages in one PDF stream filter chain
Declarations
// Delphi
property DecodeBudgetBytes: Int64;
function GetLastDecodeBudgetInfo(
out AInfo: THPDFDecodeBudgetInfo): Boolean;
// C++Builder
__property __int64 DecodeBudgetBytes;
bool __fastcall GetLastDecodeBudgetInfo(
THPDFDecodeBudgetInfo &AInfo);
Default
268435456 bytes, or 256 MiB
Aggregate accounting
Each generic filter writes through a bounded stream before data reaches its backing memory stream
- A chain such as
[/ASCII85Decode /FlateDecode]consumes the ASCII85 output plus the Flate output from one shared budget - Supported generic filters include
FlateDecode,LZWDecode,ASCIIHexDecode,ASCII85Decode, andRunLengthDecode, including their PDF abbreviations - Image predictor output shares the same budget as the preceding generic image filters
- The original encoded input is not charged because the budget measures expansion produced by decoding
- Every independent stream chain starts with a fresh per-chain budget whilst
DocumentDecodeBudgetBytessupplies the separate document-wide ceiling
Diagnostics
GetLastDecodeBudgetInfo returns the latest chain limit, accepted decoded bytes, largest stage, filter count, limit status, and the filter that exceeded the limit
THPDFDecodeBudgetInfo = record
LimitBytes: Int64;
DecodedBytes: Int64;
PeakStageBytes: Int64;
FilterCount: Integer;
Exceeded: Boolean;
ExceededFilter: AnsiString;
end;
The method returns False until at least one filter has been decoded by the document instance
Failure behaviour
Low-level decoding raises EHPDFDecodeBudgetError when a stage exceeds the aggregate budget; high-level read methods that already report failure through False or nil preserve that contract whilst GetLastDecodeBudgetInfo exposes the reason
Set DecodeBudgetBytes to zero only for trusted inputs that require unlimited per-chain expansion; negative values raise ERangeError
Delphi example
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 example
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);
}