brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.18k stars 268 forks source link

RangeError (index): Index out of range: index should be less than 89752: 1701999736 #0 Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7) #690

Open insinfo opened 1 month ago

insinfo commented 1 month ago

I'm having trouble decoding jpeg images


Future<WpImage?> insereImage(int autorId, File imageFile,
    {DateTime? data, String? legenda, String? siteUrl}) async {
  final basePath = basePathUploads;
  final now = DateTime.now();
  // post_date
  final dataPub = data ?? now;
  // Data em UTC
  final dataPubUtc = dataPub.toUtc().subtract(Duration(hours: 3));

  final ano = dataPubUtc.year;
  final mes = dataPubUtc.month;

  final siteFullurl = siteUrl ?? await getSiteUrl();

  final nomeImagemOriginal = path.basename(imageFile.path);

  final mimeType = mime(nomeImagemOriginal);

  if (mimeType == null) {
    throw Exception('Não foi possivel obter mimeType do arquivo');
  }

  final fileExtension = path.extension(nomeImagemOriginal);
  final fileName = path.basenameWithoutExtension(nomeImagemOriginal);

  Image imageOriginal;
  try {
    final imageOriginalBytes = await imageFile.readAsBytes();
    imageOriginal = decodeNamedImage(imageFile.path, imageOriginalBytes)!;
  } catch (e, s) {
    print('erro ao decodificar imagem ${imageFile.path} $e $s');
    return null;
  }
...
erro ao decodificar imagem Z:/desenvolvimento/backups/SiteAntigoPMRO_16.12.16/Portal 3.0/img/n2716.jpg RangeError (index): Index out of range: index should be less than 89752: 1701999736 #0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7)
#1      InputBuffer.readUint16 (package:image/src/util/input_buffer.dart:167:22)
#2      ExifData.read (package:image/src/exif/exif_data.dart:277:32)
#3      JpegData._readExifData (package:image/src/formats/jpeg/jpeg_data.dart:319:10)
#4      JpegData._readAppData (package:image/src/formats/jpeg/jpeg_data.dart:345:7)
#5      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:205:11)
#6      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:154:5)
#7      JpegDecoder.decode (package:image/src/formats/jpeg_decoder.dart:48:30)
#8      decodeNamedImage (package:image/src/formats/formats.dart:241:20)
#9      insereImage (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:594:21)
<asynchronous suspension>
#10     importaNoticias (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:430:25)
<asynchronous suspension>
#11     main (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:403:3)
<asynchronous suspension>

erro ao decodificar imagem Z:/desenvolvimento/backups/SiteAntigoPMRO_16.12.16/Portal 3.0/img/n2717.jpg RangeError (index): Index out of range: index should be less than 24882: 65957 #0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7)
#1      InputBuffer.readUint16 (package:image/src/util/input_buffer.dart:167:22)
#2      ExifData.read (package:image/src/exif/exif_data.dart:277:32)
#3      JpegData._readExifData (package:image/src/formats/jpeg/jpeg_data.dart:319:10)
#4      JpegData._readAppData (package:image/src/formats/jpeg/jpeg_data.dart:345:7)
#5      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:205:11)
#6      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:154:5)
#7      JpegDecoder.decode (package:image/src/formats/jpeg_decoder.dart:48:30)
#8      decodeNamedImage (package:image/src/formats/formats.dart:241:20)
#9      insereImage (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:594:21)
<asynchronous suspension>
#10     importaNoticias (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:430:25)
<asynchronous suspension>
#11     main (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:403:3)
<asynchronous suspension>

erro ao decodificar imagem Z:/desenvolvimento/backups/SiteAntigoPMRO_16.12.16/Portal 3.0/img/n2715.jpg RangeError (index): Index out of range: index should be less than 31398: 694642044 #0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7)
#1      InputBuffer.readUint16 (package:image/src/util/input_buffer.dart:167:22)
#2      ExifData.read (package:image/src/exif/exif_data.dart:277:32)
#3      JpegData._readExifData (package:image/src/formats/jpeg/jpeg_data.dart:319:10)
#4      JpegData._readAppData (package:image/src/formats/jpeg/jpeg_data.dart:345:7)
#5      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:205:11)
#6      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:154:5)
#7      JpegDecoder.decode (package:image/src/formats/jpeg_decoder.dart:48:30)
#8      decodeNamedImage (package:image/src/formats/formats.dart:241:20)
#9      insereImage (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:594:21)
<asynchronous suspension>
#10     importaNoticias (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:430:25)
<asynchronous suspension>
#11     main (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:403:3)
<asynchronous suspension>

erro ao decodificar imagem Z:/desenvolvimento/backups/SiteAntigoPMRO_16.12.16/Portal 3.0/img/n2715_2.jpg RangeError (index): Index out of range: index should be less than 27200: 1701838860 #0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7)
#1      InputBuffer.readUint16 (package:image/src/util/input_buffer.dart:167:22)
#2      ExifData.read (package:image/src/exif/exif_data.dart:277:32)
#3      JpegData._readExifData (package:image/src/formats/jpeg/jpeg_data.dart:319:10)
#4      JpegData._readAppData (package:image/src/formats/jpeg/jpeg_data.dart:345:7)
#5      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:205:11)
#6      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:154:5)
#7      JpegDecoder.decode (package:image/src/formats/jpeg_decoder.dart:48:30)
#8      decodeNamedImage (package:image/src/formats/formats.dart:241:20)
#9      insereImage (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:594:21)
<asynchronous suspension>
#10     importaNoticias (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:430:25)
<asynchronous suspension>
#11     main (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:403:3)
<asynchronous suspension>

erro ao decodificar imagem Z:/desenvolvimento/backups/SiteAntigoPMRO_16.12.16/Portal 3.0/img/n2721_2.jpg RangeError (index): Index out of range: index should be less than 33784: 33784 #0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7)
#1      InputBuffer.readUint32 (package:image/src/util/input_buffer.dart:194:22)
#2      ExifData._readEntry (package:image/src/exif/exif_data.dart:331:25)
#3      ExifData.read.<anonymous closure> (package:image/src/exif/exif_data.dart:279:30)
#4      new _GrowableList.generate (dart:core-patch/growable_array.dart:136:28)
#5      ExifData.read (package:image/src/exif/exif_data.dart:278:19)
#6      JpegData._readExifData (package:image/src/formats/jpeg/jpeg_data.dart:319:10)
#7      JpegData._readAppData (package:image/src/formats/jpeg/jpeg_data.dart:345:7)
#8      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:205:11)
#9      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:154:5)
#10     JpegDecoder.decode (package:image/src/formats/jpeg_decoder.dart:48:30)
#11     decodeNamedImage (package:image/src/formats/formats.dart:241:20)
#12     insereImage (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:594:21)
<asynchronous suspension>
#13     importaNoticias (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:430:25)
<asynchronous suspension>
#14     main (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:403:3)
<asynchronous suspension>

erro ao decodificar imagem Z:/desenvolvimento/backups/SiteAntigoPMRO_16.12.16/Portal 3.0/img/n2721_3.jpg RangeError (index): Index out of range: index should be less than 29072: 262156 #0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7)
#1      InputBuffer.readUint16 (package:image/src/util/input_buffer.dart:167:22)
#2      ExifData.read (package:image/src/exif/exif_data.dart:277:32)
#3      JpegData._readExifData (package:image/src/formats/jpeg/jpeg_data.dart:319:10)
#4      JpegData._readAppData (package:image/src/formats/jpeg/jpeg_data.dart:345:7)
#5      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:205:11)
#6      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:154:5)
#7      JpegDecoder.decode (package:image/src/formats/jpeg_decoder.dart:48:30)
#8      decodeNamedImage (package:image/src/formats/formats.dart:241:20)
#9      insereImage (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:594:21)
<asynchronous suspension>
#10     importaNoticias (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:430:25)
<asynchronous suspension>
#11     main (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:403:3)
<asynchronous suspension>

erro ao decodificar imagem Z:/desenvolvimento/backups/SiteAntigoPMRO_16.12.16/Portal 3.0/img/n2726.jpg RangeError (index): Index out of range: index should be less than 90650: 1935438718 #0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7)
#1      InputBuffer.readUint16 (package:image/src/util/input_buffer.dart:167:22)
#2      ExifData.read (package:image/src/exif/exif_data.dart:277:32)
#3      JpegData._readExifData (package:image/src/formats/jpeg/jpeg_data.dart:319:10)
#4      JpegData._readAppData (package:image/src/formats/jpeg/jpeg_data.dart:345:7)
#5      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:205:11)
#6      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:154:5)
#7      JpegDecoder.decode (package:image/src/formats/jpeg_decoder.dart:48:30)
#8      decodeNamedImage (package:image/src/formats/formats.dart:241:20)
#9      insereImage (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:594:21)
<asynchronous suspension>
#10     importaNoticias (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:430:25)
<asynchronous suspension>
#11     main (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:403:3)
<asynchronous suspension>

erro ao decodificar imagem Z:/desenvolvimento/backups/SiteAntigoPMRO_16.12.16/Portal 3.0/img/n2726_2.jpg RangeError (index): Index out of range: index should be less than 29015: 786444 #0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7)
#1      InputBuffer.readUint16 (package:image/src/util/input_buffer.dart:167:22)
#2      ExifData.read (package:image/src/exif/exif_data.dart:277:32)
#3      JpegData._readExifData (package:image/src/formats/jpeg/jpeg_data.dart:319:10)
#4      JpegData._readAppData (package:image/src/formats/jpeg/jpeg_data.dart:345:7)
#5      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:205:11)
#6      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:154:5)
#7      JpegDecoder.decode (package:image/src/formats/jpeg_decoder.dart:48:30)
#8      decodeNamedImage (package:image/src/formats/formats.dart:241:20)
#9      insereImage (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:594:21)
<asynchronous suspension>
#10     importaNoticias (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:430:25)
<asynchronous suspension>
#11     main (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:403:3)
<asynchronous suspension>

erro ao decodificar imagem Z:/desenvolvimento/backups/SiteAntigoPMRO_16.12.16/Portal 3.0/img/n2719.jpg RangeError (index): Index out of range: index should be less than 34604: 6816105 #0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7)
#1      InputBuffer.readUint16 (package:image/src/util/input_buffer.dart:167:22)
#2      ExifData.read (package:image/src/exif/exif_data.dart:277:32)
#3      JpegData._readExifData (package:image/src/formats/jpeg/jpeg_data.dart:319:10)
#4      JpegData._readAppData (package:image/src/formats/jpeg/jpeg_data.dart:345:7)
#5      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:205:11)
#6      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:154:5)
#7      JpegDecoder.decode (package:image/src/formats/jpeg_decoder.dart:48:30)
#8      decodeNamedImage (package:image/src/formats/formats.dart:241:20)
#9      insereImage (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:594:21)
<asynchronous suspension>
#10     importaNoticias (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:430:25)
<asynchronous suspension>
#11     main (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:403:3)
<asynchronous suspension>

erro ao decodificar imagem Z:/desenvolvimento/backups/SiteAntigoPMRO_16.12.16/Portal 3.0/img/n2725.jpg RangeError (index): Index out of range: index should be less than 29083: 3085975044 #0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2259:7)
#1      InputBuffer.readUint16 (package:image/src/util/input_buffer.dart:167:22)
#2      ExifData._readEntry (package:image/src/exif/exif_data.dart:329:23)
#3      ExifData.read.<anonymous closure> (package:image/src/exif/exif_data.dart:279:30)
#4      new _GrowableList.generate (dart:core-patch/growable_array.dart:136:28)
#5      ExifData.read (package:image/src/exif/exif_data.dart:278:19)
#6      JpegData._readExifData (package:image/src/formats/jpeg/jpeg_data.dart:319:10)
#7      JpegData._readAppData (package:image/src/formats/jpeg/jpeg_data.dart:345:7)
#8      JpegData._read (package:image/src/formats/jpeg/jpeg_data.dart:205:11)
#9      JpegData.read (package:image/src/formats/jpeg/jpeg_data.dart:154:5)
#10     JpegDecoder.decode (package:image/src/formats/jpeg_decoder.dart:48:30)
#11     decodeNamedImage (package:image/src/formats/formats.dart:241:20)
#12     insereImage (file:///C:/MyDartProjects/pg_query/examples/high_level/web_scraping.dart:594:21)

n2723_2 n2725 n2738 n2739

photos.zip

insinfo commented 1 month ago

image: ^4.3.0 Dart SDK version: 3.2.1

brendan-duncan commented 1 month ago

Thanks for the repo photos, I'll take a look

brendan-duncan commented 1 month ago

I pushed a fix to git