Documentation
¶
Overview ¶
Package security provides common security limits and validation utilities for all JPEG family decoders.
Index ¶
- Constants
- Variables
- func CheckBounds(index, length int) error
- func SafeRead(data []byte, pos, length int) []byte
- func SafeSlice(data []byte, start, end int) []byte
- func Validate4DDimension(dim int) error
- func ValidateBitDepth(bitDepth int) error
- func ValidateDecompLevel(level int) error
- func ValidateDimensions(width, height int) error
- func ValidateEventStreamSize(size int64) error
- func ValidateEventsPerFrame(count int) error
- func ValidateFloatExponent(exponent int) error
- func ValidateHDRDynamicRange(dynamicRange float64) error
- func ValidateInferenceIterations(iterations int) error
- func ValidateJUMBFBoxDepth(depth int) error
- func ValidateLightFieldViews(viewCount int) error
- func ValidateLineBufferSize(size int64) error
- func ValidateLinkedReferences(count int) error
- func ValidateMetadataSize(size int64) error
- func ValidateModelSize(size int64) error
- func ValidateOutputSize(width, height, channels, bytesPerSample int) error
- func ValidatePointCloudPoints(pointCount int64) error
- func ValidateSubbandSize(size int64) error
- func ValidateTensorDimensions(dims int) error
- func ValidateTileCount(count int) error
- func ValidateTimestampDelta(delta int64) error
- func ValidateToneMapIterations(iterations int) error
- func ValidateWaveletLevel(level int) error
Constants ¶
const ( // MaxOutputSize is the maximum allowed decoded image size in bytes (512 MB). MaxOutputSize = 512 << 20 // MaxImageWidth is the maximum allowed image width in pixels. MaxImageWidth = 65535 // MaxImageHeight is the maximum allowed image height in pixels. MaxImageHeight = 65535 // MaxPixelCount is the maximum number of pixels allowed (256 megapixels). MaxPixelCount = 256 << 20 // MaxImagePixels is an alias for MaxPixelCount for compatibility. MaxImagePixels = MaxPixelCount // MaxIterations is the maximum iterations allowed per loop (1 million). MaxIterations = 1 << 20 // MaxTileCount is the maximum number of tiles in tiled images. MaxTileCount = 65535 // MaxDecompLevels is the maximum wavelet decomposition levels (JPEG 2000). MaxDecompLevels = 32 // MaxChannels is the maximum number of color channels. MaxChannels = 256 // MaxBitDepth is the maximum bits per sample. MaxBitDepth = 32 // MaxMarkerLength is the maximum length for a single marker segment. MaxMarkerLength = 65535 // MaxSegmentSize is an alias for MaxMarkerLength for compatibility. MaxSegmentSize = MaxMarkerLength // MaxCodeBlockSize is the maximum code-block dimension (JPEG 2000). MaxCodeBlockSize = 1024 // MaxANSStateSize is the maximum ANS state table size (JPEG XL). MaxANSStateSize = 1 << 20 // MaxHDRDynamicRange is the maximum dynamic range in stops for HDR images. MaxHDRDynamicRange = 30 // MaxFloatExponent is the maximum float exponent allowed in HDR data. MaxFloatExponent = 127 // MaxToneMapIterations is the maximum iterations for tone mapping operators. MaxToneMapIterations = 1000 // MaxWaveletLevels is the maximum wavelet decomposition levels for JPEG XS. MaxWaveletLevels = 16 // MaxSubbandSize is the maximum size of a single wavelet subband in bytes (64 MB). MaxSubbandSize = 64 << 20 // MaxLineBufferSize is the maximum line buffer size for low-latency codecs (16 MB). MaxLineBufferSize = 16 << 20 // Max4DDimensions is the maximum dimension size for 4D light field data. Max4DDimensions = 4096 // MaxLightFieldViews is the maximum number of views in a light field image. MaxLightFieldViews = 65536 // MaxPointCloudPoints is the maximum number of points in a point cloud (100 million). MaxPointCloudPoints = 100 << 20 // MaxModelSize is the maximum neural network model size in bytes (256 MB). MaxModelSize = 256 << 20 // MaxInferenceIterations is the maximum iterations during inference. MaxInferenceIterations = 10000 // MaxTensorDimensions is the maximum number of dimensions in a tensor. MaxTensorDimensions = 8 // MaxJUMBFBoxDepth is the maximum nesting depth for JUMBF boxes. MaxJUMBFBoxDepth = 32 // MaxMetadataSize is the maximum metadata segment size in bytes (64 MB). MaxMetadataSize = 64 << 20 // MaxLinkedReferences is the maximum number of linked references (JLINK). MaxLinkedReferences = 1024 // MaxEventsPerFrame is the maximum events per frame in event-based imaging. MaxEventsPerFrame = 10 << 20 // MaxEventStreamSize is the maximum event stream size in bytes (128 MB). MaxEventStreamSize = 128 << 20 // MaxTimestampDelta is the maximum timestamp delta between events in microseconds. MaxTimestampDelta = 1 << 30 )
Security limits for all decoders. These constants prevent denial-of-service attacks from malformed images.
Variables ¶
var ( // ErrOutputTooLarge indicates the decoded output would exceed MaxOutputSize. ErrOutputTooLarge = errors.New("decoded output size exceeds maximum limit") // ErrDimensionsTooLarge indicates width or height exceeds maximum limits. ErrDimensionsTooLarge = errors.New("image dimensions exceed maximum limit") // ErrPixelCountTooLarge indicates total pixels exceed MaxPixelCount. ErrPixelCountTooLarge = errors.New("pixel count exceeds maximum limit") // ErrTooManyIterations indicates a loop exceeded MaxIterations. ErrTooManyIterations = errors.New("exceeded maximum iteration limit") // ErrTooManyTiles indicates tile count exceeds MaxTileCount. ErrTooManyTiles = errors.New("tile count exceeds maximum limit") // ErrInvalidDecompLevel indicates decomposition level exceeds MaxDecompLevels. ErrInvalidDecompLevel = errors.New("decomposition level exceeds maximum limit") // ErrTruncatedData indicates the input data is incomplete. ErrTruncatedData = errors.New("truncated or incomplete data") // ErrMalformedMarker indicates a marker segment is malformed. ErrMalformedMarker = errors.New("malformed marker segment") // ErrInvalidBitDepth indicates bit depth is outside valid range. ErrInvalidBitDepth = errors.New("invalid bit depth") // ErrZeroDimension indicates width or height is zero. ErrZeroDimension = errors.New("zero dimension not allowed") // ErrZeroChannels indicates number of channels is zero. ErrZeroChannels = errors.New("zero channels not allowed") // ErrInvalidCodeblock indicates code-block parameters are invalid. ErrInvalidCodeblock = errors.New("invalid code-block parameters") // ErrInvalidANSState indicates ANS decoder state is invalid. ErrInvalidANSState = errors.New("invalid ANS decoder state") // ErrInvalidHDRValue indicates an HDR value exceeds allowed limits. ErrInvalidHDRValue = errors.New("HDR value exceeds maximum limit") // ErrInvalidWaveletLevel indicates wavelet level exceeds maximum. ErrInvalidWaveletLevel = errors.New("wavelet level exceeds maximum limit") // ErrSubbandTooLarge indicates a wavelet subband exceeds size limit. ErrSubbandTooLarge = errors.New("wavelet subband exceeds maximum size") // ErrLineBufferTooLarge indicates line buffer exceeds size limit. ErrLineBufferTooLarge = errors.New("line buffer exceeds maximum size") // ErrTooManyViews indicates light field view count exceeds limit. ErrTooManyViews = errors.New("light field view count exceeds maximum limit") // ErrTooManyPoints indicates point cloud point count exceeds limit. ErrTooManyPoints = errors.New("point cloud point count exceeds maximum limit") // ErrModelTooLarge indicates neural network model exceeds size limit. ErrModelTooLarge = errors.New("neural network model exceeds maximum size") // ErrTensorDimensionsTooLarge indicates tensor has too many dimensions. ErrTensorDimensionsTooLarge = errors.New("tensor dimensions exceed maximum limit") // ErrJUMBFBoxTooDeep indicates JUMBF box nesting exceeds limit. ErrJUMBFBoxTooDeep = errors.New("JUMBF box nesting exceeds maximum depth") // ErrMetadataTooLarge indicates metadata segment exceeds size limit. ErrMetadataTooLarge = errors.New("metadata exceeds maximum size") // ErrTooManyReferences indicates linked references exceed limit. ErrTooManyReferences = errors.New("linked references exceed maximum limit") // ErrTooManyEvents indicates event count per frame exceeds limit. ErrTooManyEvents = errors.New("events per frame exceed maximum limit") // ErrEventStreamTooLarge indicates event stream exceeds size limit. ErrEventStreamTooLarge = errors.New("event stream exceeds maximum size") // ErrInvalidTimestampDelta indicates timestamp delta exceeds limit. ErrInvalidTimestampDelta = errors.New("timestamp delta exceeds maximum limit") )
Common security errors.
Functions ¶
func CheckBounds ¶
CheckBounds validates array access is within bounds.
func SafeSlice ¶
SafeSlice returns a safely bounded slice, preventing panics. If start or end are out of bounds, they are clamped to valid values.
func Validate4DDimension ¶
Validate4DDimension checks if a 4D dimension value is within limits.
func ValidateBitDepth ¶
ValidateBitDepth checks if bit depth is within valid range.
func ValidateDecompLevel ¶
ValidateDecompLevel checks if decomposition level is within limits.
func ValidateDimensions ¶
ValidateDimensions checks if image dimensions are within allowed limits.
func ValidateEventStreamSize ¶
ValidateEventStreamSize checks if event stream size is within limits.
func ValidateEventsPerFrame ¶
ValidateEventsPerFrame checks if event count per frame is within limits.
func ValidateFloatExponent ¶
ValidateFloatExponent checks if a float exponent is within limits.
func ValidateHDRDynamicRange ¶
ValidateHDRDynamicRange checks if the HDR dynamic range is within limits.
func ValidateInferenceIterations ¶
ValidateInferenceIterations checks if inference iteration count is within limits.
func ValidateJUMBFBoxDepth ¶
ValidateJUMBFBoxDepth checks if JUMBF box nesting depth is within limits.
func ValidateLightFieldViews ¶
ValidateLightFieldViews checks if light field view count is within limits.
func ValidateLineBufferSize ¶
ValidateLineBufferSize checks if a line buffer size is within limits.
func ValidateLinkedReferences ¶
ValidateLinkedReferences checks if linked reference count is within limits.
func ValidateMetadataSize ¶
ValidateMetadataSize checks if metadata size is within limits.
func ValidateModelSize ¶
ValidateModelSize checks if neural network model size is within limits.
func ValidateOutputSize ¶
ValidateOutputSize checks if the decoded output size is within limits.
func ValidatePointCloudPoints ¶
ValidatePointCloudPoints checks if point cloud point count is within limits.
func ValidateSubbandSize ¶
ValidateSubbandSize checks if a wavelet subband size is within limits.
func ValidateTensorDimensions ¶
ValidateTensorDimensions checks if tensor dimension count is within limits.
func ValidateTileCount ¶
ValidateTileCount checks if tile count is within limits.
func ValidateTimestampDelta ¶
ValidateTimestampDelta checks if timestamp delta is within limits.
func ValidateToneMapIterations ¶
ValidateToneMapIterations checks if tone mapping iteration count is within limits.
func ValidateWaveletLevel ¶
ValidateWaveletLevel checks if wavelet level is within limits.
Types ¶
This section is empty.