Skip to content

webp: RangeError: Index out of range #745

@leocirto

Description

@leocirto

I've been using the image package not directly, but through the PDF/Printing packages.

When generating PDFs, I'm having a hard time figuring out why some images throw the RangeError while other very similar images work perfectly.

I ultimately noticed that chances of errors are higher if the image is perfectly "sharp" (see figs). And, interestingly, the RangeError disappears after a sufficient amount of "noise" is added to the image.

In the ZIP file below, there are two similar and very simple images:

-- fig_sharp.webp ( throws RangeError )
-- fig_noisy.webp ( does not throw RangeError )

These two images were generated in GIMP.

The sharp image has only straight lines and a plain background color, saved as Lossless.

The noisy image was generated by adding a bit of noise to the sharp image with the paintbrush tool and was saved as Lossless too.

I only see the RangeError with lossless images, because (I guess) the sharpness of the original image is usually destroyed when saving with lossy compression.

Is this a bug ?? A GIMP bug ?? Appreciate any help.

Thanks for this great package

ZIP File: figs.zip

Image

fig_test.dart:

import 'package:test/test.dart';
import 'package:image/image.dart' as img; // dev_dependencies:  image: ^4.5.4

void main() {

 test( '--- TESTING IMAGE FOR Index out of range USING image PACKAGE', ( ) async {

   const List<String>figPathList = [
        'fig_noisy.webp',
        'fig_sharp.webp',
   ];

   for( final String figPath in figPathList ){
       print('\n--- TESTING $figPath');
       final cmd = img.Command( ) .. decodeWebPFile( figPath );
       await cmd.execute( );
       print('--- OK');
   }

 }  );

}

flutter test fig_test.dart:

flutter test test/unit_tests/fig_test.dart
00:02 +0: --- TESTING IMAGE FOR Index out of range USING image PACKAGE

--- TESTING fig_noisy.webp
--- OK

--- TESTING fig_sharp.webp
00:02 +0 -1: --- TESTING IMAGE FOR Index out of range USING image PACKAGE [E]
  RangeError (index): Index out of range: index should be less than 13320: 13320
  dart:typed_data                                            Uint32List.[]=
  package:image/src/formats/webp/vp8l_transform.dart 128:18  VP8LTransform.colorIndexInverseTransform
  package:image/src/formats/webp/vp8l_transform.dart 64:11   VP8LTransform.inverseTransform
  package:image/src/formats/webp/vp8l.dart 543:22            VP8L._applyInverseTransforms
  package:image/src/formats/webp/vp8l.dart 511:5             VP8L._processRows
  package:image/src/formats/webp/vp8l.dart 296:24            VP8L._decodeImageData
  package:image/src/formats/webp/vp8l.dart 58:10             VP8L.decode
  package:image/src/formats/webp_decoder.dart 105:33         WebPDecoder.decodeFrame
  package:image/src/formats/webp_decoder.dart 123:14         WebPDecoder.decode
  package:image/src/formats/formats.dart 421:24              decodeWebPFile

To run this test again: ....
00:02 +0 -1: Some tests failed.
identify -verbose fig_noisy.webp
identify -verbose fig_noisy.webp
Image:
  Filename: fig_noisy.webp
  Permissions: rw-r--r--
  Format: WEBP (WebP Image Format)
  Mime type: image/webp
  Class: DirectClass
  Geometry: 318x316+0+0
  Units: Undefined
  Colorspace: sRGB
  Type: Grayscale
  Base type: Undefined
  Endianness: Undefined
  Depth: 8-bit
  Channels: 3.0
  Channel depth:
    Red: 8-bit
    Green: 8-bit
    Blue: 8-bit
  Channel statistics:
    Pixels: 100488
    Red:
      min: 0  (0)
      max: 233 (0.913725)
      mean: 194.775 (0.763823)
      median: 233 (0.913725)
      standard deviation: 78.1853 (0.306609)
      kurtosis: 2.19827
      skewness: -1.99624
      entropy: 0.496147
    Green:
      min: 0  (0)
      max: 233 (0.913725)
      mean: 194.775 (0.763823)
      median: 233 (0.913725)
      standard deviation: 78.1853 (0.306609)
      kurtosis: 2.19827
      skewness: -1.99624
      entropy: 0.496147
    Blue:
      min: 0  (0)
      max: 233 (0.913725)
      mean: 194.775 (0.763823)
      median: 233 (0.913725)
      standard deviation: 78.1853 (0.306609)
      kurtosis: 2.19827
      skewness: -1.99624
      entropy: 0.496147
  Image statistics:
    Overall:
      min: 0  (0)
      max: 233 (0.913725)
      mean: 194.775 (0.763823)
      median: 233 (0.913725)
      standard deviation: 78.1853 (0.306609)
      kurtosis: 2.19827
      skewness: -1.99624
      entropy: 0.496147
  Colors: 83
  Histogram:
         13464: (0,0,0) #000000 black
            17: (152,152,152) #989898 srgb(152,152,152)
            50: (153,153,153) #999999 grey60
            68: (154,154,154) #9A9A9A srgb(154,154,154)
            83: (155,155,155) #9B9B9B srgb(155,155,155)
            91: (156,156,156) #9C9C9C grey61
           121: (157,157,157) #9D9D9D srgb(157,157,157)
           111: (158,158,158) #9E9E9E grey62
           142: (159,159,159) #9F9F9F srgb(159,159,159)
           123: (160,160,160) #A0A0A0 srgb(160,160,160)
           134: (161,161,161) #A1A1A1 grey63
           136: (162,162,162) #A2A2A2 srgb(162,162,162)
           141: (163,163,163) #A3A3A3 grey64
           156: (164,164,164) #A4A4A4 srgb(164,164,164)
           148: (165,165,165) #A5A5A5 srgb(165,165,165)
           125: (166,166,166) #A6A6A6 grey65
           196: (167,167,167) #A7A7A7 srgb(167,167,167)
           126: (168,168,168) #A8A8A8 grey66
           174: (169,169,169) #A9A9A9 DarkGray
           170: (170,170,170) #AAAAAA srgb(170,170,170)
           154: (171,171,171) #ABABAB grey67
           176: (172,172,172) #ACACAC srgb(172,172,172)
           165: (173,173,173) #ADADAD grey68
           181: (174,174,174) #AEAEAE srgb(174,174,174)
           188: (175,175,175) #AFAFAF srgb(175,175,175)
           161: (176,176,176) #B0B0B0 grey69
           193: (177,177,177) #B1B1B1 srgb(177,177,177)
           209: (178,178,178) #B2B2B2 srgb(178,178,178)
           186: (179,179,179) #B3B3B3 grey70
           190: (180,180,180) #B4B4B4 srgb(180,180,180)
           186: (181,181,181) #B5B5B5 grey71
           213: (182,182,182) #B6B6B6 srgb(182,182,182)
           179: (183,183,183) #B7B7B7 srgb(183,183,183)
           212: (184,184,184) #B8B8B8 grey72
           207: (185,185,185) #B9B9B9 srgb(185,185,185)
           203: (186,186,186) #BABABA grey73
           249: (187,187,187) #BBBBBB srgb(187,187,187)
           251: (188,188,188) #BCBCBC srgb(188,188,188)
           191: (189,189,189) #BDBDBD grey74
           243: (190,190,190) #BEBEBE grey
           244: (191,191,191) #BFBFBF grey75
           224: (192,192,192) #C0C0C0 silver
           229: (193,193,193) #C1C1C1 srgb(193,193,193)
           256: (194,194,194) #C2C2C2 grey76
           210: (195,195,195) #C3C3C3 srgb(195,195,195)
           307: (196,196,196) #C4C4C4 grey77
           232: (197,197,197) #C5C5C5 srgb(197,197,197)
           257: (198,198,198) #C6C6C6 srgb(198,198,198)
           287: (199,199,199) #C7C7C7 grey78
           269: (200,200,200) #C8C8C8 srgb(200,200,200)
           307: (201,201,201) #C9C9C9 grey79
           280: (202,202,202) #CACACA srgb(202,202,202)
           277: (203,203,203) #CBCBCB srgb(203,203,203)
           337: (204,204,204) #CCCCCC grey80
           296: (205,205,205) #CDCDCD srgb(205,205,205)
           359: (206,206,206) #CECECE srgb(206,206,206)
           305: (207,207,207) #CFCFCF grey81
           350: (208,208,208) #D0D0D0 srgb(208,208,208)
           380: (209,209,209) #D1D1D1 grey82
           308: (210,210,210) #D2D2D2 srgb(210,210,210)
           330: (211,211,211) #D3D3D3 LightGray
           447: (212,212,212) #D4D4D4 grey83
           441: (213,213,213) #D5D5D5 srgb(213,213,213)
           450: (214,214,214) #D6D6D6 grey84
           420: (215,215,215) #D7D7D7 srgb(215,215,215)
           431: (216,216,216) #D8D8D8 srgb(216,216,216)
           583: (217,217,217) #D9D9D9 grey85
           424: (218,218,218) #DADADA srgb(218,218,218)
           761: (219,219,219) #DBDBDB grey86
           629: (220,220,220) #DCDCDC gainsboro
           747: (221,221,221) #DDDDDD srgb(221,221,221)
           491: (222,222,222) #DEDEDE grey87
           830: (223,223,223) #DFDFDF srgb(223,223,223)
           671: (224,224,224) #E0E0E0 grey88
          1208: (225,225,225) #E1E1E1 srgb(225,225,225)
           779: (226,226,226) #E2E2E2 srgb(226,226,226)
          1083: (227,227,227) #E3E3E3 grey89
           721: (228,228,228) #E4E4E4 srgb(228,228,228)
          2035: (229,229,229) #E5E5E5 grey90
          1004: (230,230,230) #E6E6E6 srgb(230,230,230)
          2679: (231,231,231) #E7E7E7 srgb(231,231,231)
          1952: (232,232,232) #E8E8E8 grey91
         55945: (233,233,233) #E9E9E9 srgb(233,233,233)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33,0.03)
    green primary: (0.3,0.6,0.1)
    blue primary: (0.15,0.06,0.79)
    white point: (0.3127,0.329,0.3583)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 318x316+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Quality: 100
  Orientation: Undefined
  Properties:
    date:create: 2025-06-11T18:47:30+00:00
    date:modify: 2025-06-11T18:24:17+00:00
    date:timestamp: 2025-06-11T18:58:31+00:00
    signature: 522adfcca49d97add5330d2ec5b3a0bb714b272ee5bfd543f66dffd44067e2eb
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 5640B
  Number pixels: 100488
  Pixel cache type: Memory
  Pixels per second: 12.483MP
  User time: 0.010u
  Elapsed time: 0:01.008
  Version: ImageMagick 7.1.1-47 Q16-HDRI x86_64 22763 https://imagemagick.org
identify -verbose fig_sharp.webp
identify -verbose fig_sharp.webp
Image:
  Filename: fig_sharp.webp
  Permissions: rw-r--r--
  Format: WEBP (WebP Image Format)
  Mime type: image/webp
  Class: DirectClass
  Geometry: 318x316+0+0
  Units: Undefined
  Colorspace: sRGB
  Type: Grayscale
  Base type: Undefined
  Endianness: Undefined
  Depth: 8-bit
  Channels: 3.0
  Channel depth:
    Red: 8-bit
    Green: 8-bit
    Blue: 8-bit
  Channel statistics:
    Pixels: 100488
    Red:
      min: 0  (0)
      max: 233 (0.913725)
      mean: 201.781 (0.791299)
      median: 233 (0.913725)
      standard deviation: 79.3689 (0.311251)
      kurtosis: 2.61806
      skewness: -2.14896
      entropy: 0.56827
    Green:
      min: 0  (0)
      max: 233 (0.913725)
      mean: 201.781 (0.791299)
      median: 233 (0.913725)
      standard deviation: 79.3689 (0.311251)
      kurtosis: 2.61806
      skewness: -2.14896
      entropy: 0.56827
    Blue:
      min: 0  (0)
      max: 233 (0.913725)
      mean: 201.781 (0.791299)
      median: 233 (0.913725)
      standard deviation: 79.3689 (0.311251)
      kurtosis: 2.61806
      skewness: -2.14896
      entropy: 0.56827
  Image statistics:
    Overall:
      min: 0  (0)
      max: 233 (0.913725)
      mean: 201.781 (0.791299)
      median: 233 (0.913725)
      standard deviation: 79.3689 (0.311251)
      kurtosis: 2.61806
      skewness: -2.14896
      entropy: 0.56827
  Colors: 2
  Histogram:
         13464: (0,0,0) #000000 black
         87024: (233,233,233) #E9E9E9 srgb(233,233,233)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33,0.03)
    green primary: (0.3,0.6,0.1)
    blue primary: (0.15,0.06,0.79)
    white point: (0.3127,0.329,0.3583)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 318x316+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Quality: 100
  Orientation: Undefined
  Properties:
    date:create: 2025-06-11T18:47:38+00:00
    date:modify: 2025-06-11T18:23:11+00:00
    date:timestamp: 2025-06-11T18:58:36+00:00
    signature: 2e1e69e148ade0b0174580685a9914ea8784627c27ba7e138192e7ce2c8c2ea6
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 60B
  Number pixels: 100488
  Pixel cache type: Memory
  Pixels per second: 16.6816MP
  User time: 0.020u
  Elapsed time: 0:01.006
  Version: ImageMagick 7.1.1-47 Q16-HDRI x86_64 22763 https://imagemagick.org

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions