1

I'm having an issue where JPGs are seemingly being corrupted when served.

Curiously, its not all JPG images on my site, only about 5% of them. Here's what a corrupted one looks like:

enter image description here

The bottom half is cutoff. This is what jpeginfo on that file returns:

FS0005-2yme9un7m1rme75z1ek074.jpg  250 x 250  24bit JFIF  N   40099  Corrupt JPEG data: premature end of data segment  Invalid JPEG file structure: two SOI markers  [ERROR]

However, if I download the exact same image using wget, or just copy it directly off the server, it looks fine and appears not to be corrupted:

FS0005-2yme9un7m1rme75z1ek074.jpg  250 x 250  24bit JFIF  N   40099  [OK]

This is what curl -I returns:

HTTP/1.1 200 OK
Date: Wed, 08 Jul 2015 11:05:15 GMT
Server: LiteSpeed
Accept-Ranges: bytes
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
Last-Modified: Wed, 08 Jul 2015 08:58:42 GMT
Content-Type: image/jpeg
Content-Length: 40099
Access-Control-Allow-Origin: *
Cache-Control: public, max-age=604800
Expires: Wed, 15 Jul 2015 11:05:15 GMT

The server is Red Hat 4.4.7-4, the images have been uploaded via WordPress and resized with bfi_thumb

anthonygore
  • 4,722
  • 4
  • 31
  • 30
  • You might hit maximum memory or something in the resize script. What is this configuration on your system? – OptimusCrime Jul 08 '15 at 11:21
  • PHP memory limit is 64M, is that what you mean? – anthonygore Jul 08 '15 at 11:33
  • does apache error log say anything strange? – JohnKiller Jul 08 '15 at 12:12
  • Could be the "Accept-Ranges: bytes" header, instructing the client that it accepts ranged requests. My guess is it doesn't really support it, and starts (re-)sending the file from the start, as shown by the "two SOI markers" (Start of Image markers). `wget` probably doesn't use ranges, and just reads the file in one go, and thus does not run into the issue. Have a look at the headers the client sends in case of the corrupted downloads. – Harald K Jul 08 '15 at 17:28
  • Can you put a direct link to that "corrupted" jpeg file. Seems error is in the bytes so they need analysing. Anyways, the error tells you there's two `FF D8` bytes found in mid-image. `FF D8` really means "official JPEG data starts here" so I think your system cuts out when it meets another `FF D8` whereas it should not stop until it sees `FF D9` (official JPEG end). No reason to stop since its possible for a mid-stream byte to be `xFF` and then next following byte is `xD8`. It happens and here for you its making that 5% not work. **Is there a server setting to Ignore errors and Continue?** – VC.One Jul 12 '15 at 14:06

0 Answers0