bimg icon indicating copy to clipboard operation
bimg copied to clipboard

convert to webp, bad images

Open kgdev opened this issue 7 years ago • 15 comments

bad image

When doing resizing in http server with some concurrent requests, sometimes the resizing will return a corrupted image. See the above.

kgdev avatar Jun 07 '17 14:06 kgdev

just try to use vegeta attack to simulate high concurrent requests. the server side will return various errors:

Caused by: VipsJpeg: Not a JPEG file: starts with 0x52 0x49 Vipvips cache+: cast in=((VipsImage*) 0x1e9897d0) out=((VipsImage*) 0x4957e660) format=((VipsBandFormat) VIPS_FORMAT_UCHAR) - sJpeg: Not a JPEG file: starts with 0xe7 0xeb VipsJpeg: Not a JPEG file: starts with 0x54 0x03 VipsJpeg: Not a JPEG file: starts with 0xc4 0x21

(bimg:81679): VIPS-WARNING **: read gave 1 warnings

(bimg:81679): VIPS-WARNING **:

kgdev avatar Jun 12 '17 07:06 kgdev

Caused by: VipsJpeg: Corrupt JPEG data: premature end of data segment VipsJpeg: Corrupt JPEG data: 47 extraneous bytes before marker 0xd0 VipsJpeg: Corrupt JPEG data: 1052021 extraneous bytes before marker 0xd4 VipsJpeg: Corrupt JPEG data: 14800 extraneous bytes before marker 0xd5 VipsJpeg: Corrupt JPEG data: bad Huffman code VipsJpeg: Corrupt JPEG data: 205623 extraneous bytes before marker 0xd6 VipsJpeg: Corrupt JPEG data: premature end of data segment VipsJpeg: Corrupt JPEG data: 5192 extraneous bytes before marker 0xd5 VipsJpeg: Corrupt JPEG data: 206095 extraneous bytes before marker 0xd5 VipsJpeg: Corrupt JPEG data: 12376 extraneous bytes before marker 0xd4 VipsJpeg: Corrupt JPEG data: 605236 extraneous bytes before marker 0xd6 VipsJpeg: Corrupt JPEG data: 906390 extraneous bytes before marker 0xd7 VipsJpeg: Corrupt JPEG data: 11798 extraneous bytes before marker 0xd6 VipsJpeg: Corrupt JPEG data: premature end of data segment VipsJpeg: Corrupt JPEG data: premature end of data segment VipsJpeg: Corrupt JPEG data: 175547 extraneous bytes before marker 0xd2 VipsJpeg: Not a JPEG file: starts with 0x00 0x00 VipsJpeg: Corrupt JPEG data: premature end of data segment

kgdev avatar Jun 12 '17 07:06 kgdev

https://github.com/jcupitt/libvips/issues/675

kgdev avatar Jun 12 '17 10:06 kgdev

This seems to be a really serious bug.

kgdev avatar Jun 12 '17 10:06 kgdev

In vips.go, length := C.size_t(len(buf)) imageBuf := unsafe.Pointer(&buf[0]) --> imageBuf := C.CBytes(buf) err := C.vips_init_image(imageBuf, length, C.int(imageType), &image)

kgdev avatar Jun 12 '17 13:06 kgdev

image, imageType, err := loadImage(buf). The buf is garbage collected too early.

kgdev avatar Jun 12 '17 14:06 kgdev

runtime.KeepAlive(p) is needed.

kgdev avatar Jun 12 '17 14:06 kgdev

@kgdev I dunno if this test case is good enough to reproduce it: https://gist.github.com/greut/c4cc1310131af9b4b939a136fbdbd695

  • libvips: "8.6.0"
  • bimg: "1.0.9"

greut avatar Jun 12 '17 21:06 greut

Yes, I think it's quite easy to repro.

kgdev avatar Jun 13 '17 00:06 kgdev

mmm... it definitively looks like a legit bug. @kirillDanshin are you interesting in providing the fix? Otherwise I will work on that.

tomas-fp avatar Jun 16 '17 11:06 tomas-fp

@kgdev are you interested in providing a PR? That would accelerate the process.

tomas-fp avatar Jun 19 '17 14:06 tomas-fp

https://github.com/h2non/bimg/pull/162/files

kgdev avatar Jun 20 '17 00:06 kgdev

What is the status of this issue?

eriklott avatar Jul 26 '17 15:07 eriklott

It would be fixed anytime soon. Still need to test things and update the PR.

tomas-fp avatar Jul 26 '17 15:07 tomas-fp

When I try to convert the image from jpeg to webp using the webp package, the resulting webp image gets blurred and is unusable. I think this is related to the above stated issue. Is there any update on the same?

colt005 avatar Mar 18 '22 06:03 colt005