@@ -5,6 +5,8 @@ namespace PrivatePdfConverter.Services;
55
66public static class FileService
77{
8+ // Conservative defaults chosen to allow typical high-resolution images
9+ // while rejecting obviously pathological dimensions before full decode.
810 private const ulong MaxWidth = 10_000 ;
911 private const ulong MaxHeight = 10_000 ;
1012 private const ulong MaxArea = 100_000_000 ;
@@ -17,7 +19,7 @@ public static class FileService
1719 public static bool IsImage ( this string ? extension )
1820 => ! string . IsNullOrEmpty ( extension ) && ValidExtensions . Contains ( extension . ToLower ( ) [ 1 ..] ) ;
1921
20- public static MagickImage LoadValidatedImage ( string path )
22+ public static MagickImage ? LoadValidatedImage ( string path )
2123 {
2224 using var headerImage = new MagickImage ( ) ;
2325 headerImage . Ping ( path ) ;
@@ -28,13 +30,19 @@ public static MagickImage LoadValidatedImage(string path)
2830
2931 if ( width == 0 || height == 0 )
3032 {
31- throw new InvalidDataException ( $ "Image '{ path } ' has invalid dimensions { width } x{ height } .") ;
33+ Log . Logger . Error ( "Image '{Path}' has invalid dimensions {Width}x{Height}." , path , width , height ) ;
34+ return null ;
3235 }
3336
34- if ( ( ulong ) width > MaxWidth || ( ulong ) height > MaxHeight || area > MaxArea )
37+ if ( width > MaxWidth || height > MaxHeight || area > MaxArea )
3538 {
36- throw new InvalidDataException (
37- $ "Image '{ path } ' exceeds the supported limits ({ width } x{ height } , area { area } ).") ;
39+ Log . Logger . Error (
40+ "Image '{Path}' exceeds the supported limits ({Width}x{Height}, area {Area})." ,
41+ path ,
42+ width ,
43+ height ,
44+ area ) ;
45+ return null ;
3846 }
3947
4048 return new MagickImage ( path ) ;
0 commit comments