Documentation
¶
Overview ¶
Package security provides security validation for JPEG 2000 parsing
Index ¶
- Constants
- Variables
- func SafeAdd(a, b int) (int, bool)
- func SafeMultiply(a, b int) (int, bool)
- func SafeSubtract(a, b int) (int, bool)
- func ValidateCOD(decompositionLevels, codeBlockWidth, codeBlockHeight int) error
- func ValidateSIZ(width, height, tileWidth, tileHeight, xOffset, yOffset, components int) error
- type Validator
- func (v *Validator) CheckIteration() error
- func (v *Validator) CountSegment() error
- func (v *Validator) EnterBox() error
- func (v *Validator) ExitBox()
- func (v *Validator) Reset()
- func (v *Validator) ResetIteration()
- func (v *Validator) SetMaxMemory(max uint64)
- func (v *Validator) TrackPixels(width, height, components int) error
- func (v *Validator) ValidateAllocation(size uint64) error
- func (v *Validator) ValidateBitDepth(depth int) error
- func (v *Validator) ValidateCodeBlockSize(width, height int) error
- func (v *Validator) ValidateDecompositionLevels(levels int) error
- func (v *Validator) ValidateImageSize(width, height int) error
- func (v *Validator) ValidateNumComponents(n int) error
- func (v *Validator) ValidateNumLayers(layers int) error
- func (v *Validator) ValidateNumTiles(n int) error
- func (v *Validator) ValidatePrecinctSize(width, height int) error
- func (v *Validator) ValidateSegmentLength(length int) error
- func (v *Validator) ValidateTileSize(width, height int) error
Constants ¶
const ( // MaxImageWidth is the maximum image width MaxImageWidth = 65535 MaxImageHeight = 65535 MaxImageArea = 268435456 // 256 megapixels // MaxComponents is the maximum number of components MaxComponents = 16384 // MaxTileWidth is the maximum tile width MaxTileWidth = 65535 MaxTileHeight = 65535 MaxTiles = 65535 // MaxDecompositionLevels is the maximum number of decomposition levels MaxDecompositionLevels = 32 MaxResolutionLevels = 33 // MaxCodeBlockSize is the maximum code block size (Width * Height) MaxCodeBlockSize = 4096 MaxCodeBlockDim = 64 // Max dimension in either direction // MaxPrecinctSize is the maximum precinct size MaxPrecinctSize = 32768 // MaxQualityLayers is the maximum number of quality layers MaxQualityLayers = 16384 // MaxSegmentLength is the maximum segment length (64 MB) MaxSegmentLength = 67108864 // MaxBoxNestingDepth is the maximum box nesting depth to prevent infinite loops MaxBoxNestingDepth = 32 MaxMarkerSegments = 65535 MaxIterations = 1000000 )
Security limits to prevent resource exhaustion attacks
Variables ¶
var ( ErrImageTooLarge = errors.New("image dimensions exceed maximum allowed") ErrTooManyComponents = errors.New("number of components exceeds maximum") ErrTooManyTiles = errors.New("number of tiles exceeds maximum") ErrTileTooLarge = errors.New("tile dimensions exceed maximum") ErrTooManyLayers = errors.New("number of quality layers exceeds maximum") ErrCodeBlockTooLarge = errors.New("code block size exceeds maximum") ErrPrecinctTooLarge = errors.New("precinct size exceeds maximum") ErrTooManyDecompLevels = errors.New("decomposition levels exceed maximum") ErrSegmentTooLarge = errors.New("segment length exceeds maximum") ErrIntegerOverflow = errors.New("integer overflow detected") ErrNestingTooDeep = errors.New("box nesting depth exceeds maximum") ErrInvalidDimensions = errors.New("invalid dimensions (zero or negative)") ErrInvalidBitDepth = errors.New("invalid bit depth") )
Errors
Functions ¶
func SafeMultiply ¶
SafeMultiply performs multiplication with overflow checking
func SafeSubtract ¶
SafeSubtract performs subtraction with overflow checking
func ValidateCOD ¶
ValidateCOD validates COD marker parameters
func ValidateSIZ ¶
ValidateSIZ validates SIZ marker parameters
Types ¶
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator provides security validation for JPEG 2000 parsing
func (*Validator) CheckIteration ¶
CheckIteration guards against infinite loops
func (*Validator) CountSegment ¶
CountSegment tracks number of marker segments parsed
func (*Validator) ResetIteration ¶
func (v *Validator) ResetIteration()
ResetIteration resets the iteration counter
func (*Validator) SetMaxMemory ¶
SetMaxMemory sets the maximum memory allocation limit
func (*Validator) TrackPixels ¶
TrackPixels tracks total pixels for memory accounting
func (*Validator) ValidateAllocation ¶
ValidateAllocation checks if a memory allocation is safe
func (*Validator) ValidateBitDepth ¶
ValidateBitDepth validates component bit depth
func (*Validator) ValidateCodeBlockSize ¶
ValidateCodeBlockSize validates code block dimensions
func (*Validator) ValidateDecompositionLevels ¶
ValidateDecompositionLevels validates the number of decomposition levels
func (*Validator) ValidateImageSize ¶
ValidateImageSize validates image dimensions
func (*Validator) ValidateNumComponents ¶
ValidateNumComponents validates the number of components
func (*Validator) ValidateNumLayers ¶
ValidateNumLayers validates the number of quality layers
func (*Validator) ValidateNumTiles ¶
ValidateNumTiles validates the number of tiles
func (*Validator) ValidatePrecinctSize ¶
ValidatePrecinctSize validates precinct dimensions
func (*Validator) ValidateSegmentLength ¶
ValidateSegmentLength validates marker segment length
func (*Validator) ValidateTileSize ¶
ValidateTileSize validates tile dimensions