]> git.lizzy.rs Git - plan9front.git/commitdiff
jpg: treat EOF as EOI marker
authorAlex Musolino <alex@musolino.id.au>
Sat, 31 Oct 2020 05:14:49 +0000 (15:44 +1030)
committerAlex Musolino <alex@musolino.id.au>
Sat, 31 Oct 2020 05:14:49 +0000 (15:44 +1030)
Some jpegs, rightly or wrongly, do not contain an EOI marker.  This
causes jpg(1) to bail out even after correctly parsing the entire
image.

sys/src/cmd/jpg/readjpg.c

index 942b581e931c1ed39e613b8a7ea8130d262f8f64..0d50802e345ded08ddee400e92b9c671b27c1966 100644 (file)
@@ -389,8 +389,12 @@ readbyte(Header *h)
        if(h->peek >= 0){
                x = h->peek;
                h->peek = -1;
-       }else if(Bread(h->fd, &x, 1) != 1)
-               jpgerror(h, readerr);
+       }else
+               switch(Bread(h->fd, &x, 1)){
+               case 0: return -1;
+               case 1: break;
+               default: jpgerror(h, readerr);
+               }
        return x;
 }
 
@@ -403,6 +407,8 @@ marker(Header *h)
 Again:
        while((c=readbyte(h)) == 0)
                ;
+       if(c < 0)
+               return EOI;
        if(c != 0xFF)
                goto Again;
        while(c == 0xFF)