unzip/zipfs: skip over variable length comment in end of table of content record

This commit is contained in:
cinap_lenrek 2012-08-06 02:25:22 +02:00
parent 5eec707368
commit 6baaf0a773
2 changed files with 19 additions and 10 deletions

View file

@ -529,7 +529,7 @@ static int
findCDir(Biobuf *bin, char *file) findCDir(Biobuf *bin, char *file)
{ {
vlong ecoff; vlong ecoff;
long off, size, m; long off, size;
int entries, zclen, dn, ds, de; int entries, zclen, dn, ds, de;
ecoff = Bseek(bin, -ZECHeadSize, 2); ecoff = Bseek(bin, -ZECHeadSize, 2);
@ -540,11 +540,16 @@ findCDir(Biobuf *bin, char *file)
} }
if(setjmp(zjmp)) if(setjmp(zjmp))
return -1; return -1;
off = 0;
if((m=get4(bin)) != ZECHeader){ while(get4(bin) != ZECHeader){
fprint(2, "unzip: bad magic number for table of contents of %s: %#.8lx\n", file, m); if(ecoff <= 0 || off >= 1024){
longjmp(seekjmp, 1); fprint(2, "unzip: cannot find end of table of contents in %s\n", file);
return -1; longjmp(seekjmp, 1);
return -1;
}
off++;
ecoff--;
Bseek(bin, ecoff, 0);
} }
dn = get2(bin); dn = get2(bin);
ds = get2(bin); ds = get2(bin);

View file

@ -189,10 +189,14 @@ findCDir(Biobuf *bin)
ecoff = Bseek(bin, -ZECHeadSize, 2); ecoff = Bseek(bin, -ZECHeadSize, 2);
if(ecoff < 0) if(ecoff < 0)
sysfatal("can't seek to header"); sysfatal("can't seek to header");
off = 0;
if(get4(bin) != ZECHeader) while(get4(bin) != ZECHeader){
sysfatal("bad magic number on directory"); if(ecoff <= 0 || off >= 1024)
sysfatal("bad magic number");
off++;
ecoff--;
Bseek(bin, ecoff, 0);
}
get2(bin); get2(bin);
get2(bin); get2(bin);
get2(bin); get2(bin);