do not assume osection[0].rawdataptr > 0 during decompression

This commit is contained in:
László Molnár 2006-06-08 16:52:54 +02:00
parent ee9f8c184b
commit 2eb91f9b91
2 changed files with 14 additions and 6 deletions

View File

@ -2508,16 +2508,20 @@ void PackArmPe::unpack(OutputFile *fo)
// write decompressed file // write decompressed file
if (fo) if (fo)
{ {
unsigned ic;
for (ic = 0; ic < objs && osection[ic].rawdataptr == 0; ic++)
;
ibuf.dealloc(); ibuf.dealloc();
ibuf.alloc(osection[0].rawdataptr); ibuf.alloc(osection[ic].rawdataptr);
ibuf.clear(); ibuf.clear();
infoHeader("[Writing uncompressed file]"); infoHeader("[Writing uncompressed file]");
// write loader + compressed file // write loader + compressed file
fo->write(&oh,sizeof(oh)); fo->write(&oh,sizeof(oh));
fo->write(osection,objs * sizeof(pe_section_t)); fo->write(osection,objs * sizeof(pe_section_t));
fo->write(ibuf,osection[0].rawdataptr - fo->getBytesWritten()); fo->write(ibuf,osection[ic].rawdataptr - fo->getBytesWritten());
for(unsigned ic = 0; ic < objs; ic++) for (ic = 0; ic < objs; ic++)
if (osection[ic].rawdataptr) if (osection[ic].rawdataptr)
fo->write(obuf + osection[ic].vaddr - rvamin,ALIGN_UP(osection[ic].size,oh.filealign)); fo->write(obuf + osection[ic].vaddr - rvamin,ALIGN_UP(osection[ic].size,oh.filealign));
copyOverlay(fo, overlay, &obuf); copyOverlay(fo, overlay, &obuf);

View File

@ -2600,16 +2600,20 @@ void PackW32Pe::unpack(OutputFile *fo)
// write decompressed file // write decompressed file
if (fo) if (fo)
{ {
unsigned ic;
for (ic = 0; ic < objs && osection[ic].rawdataptr == 0; ic++)
;
ibuf.dealloc(); ibuf.dealloc();
ibuf.alloc(osection[0].rawdataptr); ibuf.alloc(osection[ic].rawdataptr);
ibuf.clear(); ibuf.clear();
infoHeader("[Writing uncompressed file]"); infoHeader("[Writing uncompressed file]");
// write loader + compressed file // write loader + compressed file
fo->write(&oh,sizeof(oh)); fo->write(&oh,sizeof(oh));
fo->write(osection,objs * sizeof(pe_section_t)); fo->write(osection,objs * sizeof(pe_section_t));
fo->write(ibuf,osection[0].rawdataptr - fo->getBytesWritten()); fo->write(ibuf,osection[ic].rawdataptr - fo->getBytesWritten());
for(unsigned ic = 0; ic < objs; ic++) for (ic = 0; ic < objs; ic++)
if (osection[ic].rawdataptr) if (osection[ic].rawdataptr)
fo->write(obuf + osection[ic].vaddr - rvamin,ALIGN_UP(osection[ic].size,oh.filealign)); fo->write(obuf + osection[ic].vaddr - rvamin,ALIGN_UP(osection[ic].size,oh.filealign));
copyOverlay(fo, overlay, &obuf); copyOverlay(fo, overlay, &obuf);