From 2eb91f9b91fdaef5517f4872fceb1dbc7eb45403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Moln=C3=A1r?= Date: Thu, 8 Jun 2006 16:52:54 +0200 Subject: [PATCH] do not assume osection[0].rawdataptr > 0 during decompression --- src/p_armpe.cpp | 10 +++++++--- src/p_w32pe.cpp | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/p_armpe.cpp b/src/p_armpe.cpp index cbfcfdfe..66b8f2ef 100644 --- a/src/p_armpe.cpp +++ b/src/p_armpe.cpp @@ -2508,16 +2508,20 @@ void PackArmPe::unpack(OutputFile *fo) // write decompressed file if (fo) { + unsigned ic; + for (ic = 0; ic < objs && osection[ic].rawdataptr == 0; ic++) + ; + ibuf.dealloc(); - ibuf.alloc(osection[0].rawdataptr); + ibuf.alloc(osection[ic].rawdataptr); ibuf.clear(); infoHeader("[Writing uncompressed file]"); // write loader + compressed file fo->write(&oh,sizeof(oh)); fo->write(osection,objs * sizeof(pe_section_t)); - fo->write(ibuf,osection[0].rawdataptr - fo->getBytesWritten()); - for(unsigned ic = 0; ic < objs; ic++) + fo->write(ibuf,osection[ic].rawdataptr - fo->getBytesWritten()); + for (ic = 0; ic < objs; ic++) if (osection[ic].rawdataptr) fo->write(obuf + osection[ic].vaddr - rvamin,ALIGN_UP(osection[ic].size,oh.filealign)); copyOverlay(fo, overlay, &obuf); diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index e86a7491..73157be3 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -2600,16 +2600,20 @@ void PackW32Pe::unpack(OutputFile *fo) // write decompressed file if (fo) { + unsigned ic; + for (ic = 0; ic < objs && osection[ic].rawdataptr == 0; ic++) + ; + ibuf.dealloc(); - ibuf.alloc(osection[0].rawdataptr); + ibuf.alloc(osection[ic].rawdataptr); ibuf.clear(); infoHeader("[Writing uncompressed file]"); // write loader + compressed file fo->write(&oh,sizeof(oh)); fo->write(osection,objs * sizeof(pe_section_t)); - fo->write(ibuf,osection[0].rawdataptr - fo->getBytesWritten()); - for(unsigned ic = 0; ic < objs; ic++) + fo->write(ibuf,osection[ic].rawdataptr - fo->getBytesWritten()); + for (ic = 0; ic < objs; ic++) if (osection[ic].rawdataptr) fo->write(obuf + osection[ic].vaddr - rvamin,ALIGN_UP(osection[ic].size,oh.filealign)); copyOverlay(fo, overlay, &obuf);