bimg
bimg copied to clipboard
convert to webp, bad images
When doing resizing in http server with some concurrent requests, sometimes the resizing will return a corrupted image. See the above.
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 **:
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
https://github.com/jcupitt/libvips/issues/675
This seems to be a really serious bug.
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)
image, imageType, err := loadImage(buf). The buf is garbage collected too early.
runtime.KeepAlive(p) is needed.
@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"
Yes, I think it's quite easy to repro.
mmm... it definitively looks like a legit bug. @kirillDanshin are you interesting in providing the fix? Otherwise I will work on that.
@kgdev are you interested in providing a PR? That would accelerate the process.
https://github.com/h2non/bimg/pull/162/files
What is the status of this issue?
It would be fixed anytime soon. Still need to test things and update the PR.
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?