File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -1016,13 +1016,23 @@ function decode(jpegData, opts) {
1016
1016
decoder . colorTransform = opts . colorTransform ;
1017
1017
1018
1018
var channels = ( opts . formatAsRGBA ) ? 4 : 3 ;
1019
- var image = {
1020
- width : decoder . width ,
1021
- height : decoder . height ,
1022
- data : opts . useTArray ?
1023
- new Uint8Array ( decoder . width * decoder . height * channels ) :
1024
- new Buffer ( decoder . width * decoder . height * channels )
1025
- } ;
1019
+ var bytesNeeded = decoder . width * decoder . height * channels ;
1020
+ try {
1021
+ var image = {
1022
+ width : decoder . width ,
1023
+ height : decoder . height ,
1024
+ data : opts . useTArray ?
1025
+ new Uint8Array ( bytesNeeded ) :
1026
+ new Buffer ( bytesNeeded )
1027
+ } ;
1028
+ } catch ( err ) {
1029
+ if ( err instanceof RangeError ) {
1030
+ throw new Error ( "Could not allocate enough memory for the image. " +
1031
+ "Required: " + bytesNeeded ) ;
1032
+ } else {
1033
+ throw err ;
1034
+ }
1035
+ }
1026
1036
1027
1037
decoder . copyToImageData ( image , opts . formatAsRGBA ) ;
1028
1038
You can’t perform that action at this time.
0 commit comments