Prerequisites
ImageSharp version
4.0.0 (commit: ff36e83) (not a regression, also present on 3.1.12)
Other ImageSharp packages and versions
N/A
Environment (Operating system, version and so on)
Ubuntu/Windows
.NET Framework version
.NET 10
Description
Loading a Netpbm image (PGM/PPM, ASCII or binary) with a maxval header field of 0 throws System.DivideByZeroException from PbmDecoderCore.ProcessUpscaling.
The standard puts this value to be less than 65536, and more than zero, so the input is malformed - and the decoder should surface it as InvalidImageContentException.
Any invalid value would trigger the same effect. In the current code maxPixelValue isn't validated after parsing, so 0 (either literally, or the parser's default when the field starts with a non-digit) ends up as the divisor in ProcessUpscaling.
Steps to Reproduce
var bytes = "P2 1 1 0\n0"u8.ToArray();
using var ms = new MemoryStream(bytes);
using var image = Image.Load<Rgba32>(ms); // throws DivideByZeroException
Reproduces with all four Netpbm magics (P2, P3, P5, P6).
Images
N/A. Example is self contained.
Prerequisites
DEBUGandRELEASEmodeImageSharp version
4.0.0 (commit: ff36e83) (not a regression, also present on 3.1.12)
Other ImageSharp packages and versions
N/A
Environment (Operating system, version and so on)
Ubuntu/Windows
.NET Framework version
.NET 10
Description
Loading a Netpbm image (PGM/PPM, ASCII or binary) with a
maxvalheader field of0throwsSystem.DivideByZeroExceptionfromPbmDecoderCore.ProcessUpscaling.The standard puts this value to be less than 65536, and more than zero, so the input is malformed - and the decoder should surface it as
InvalidImageContentException.Any invalid value would trigger the same effect. In the current code
maxPixelValueisn't validated after parsing, so 0 (either literally, or the parser's default when the field starts with a non-digit) ends up as the divisor inProcessUpscaling.Steps to Reproduce
Reproduces with all four Netpbm magics (
P2,P3,P5,P6).Images
N/A. Example is self contained.