From cf3f4b0ae8966c63935d6dbfaa400cafafbeb2c7 Mon Sep 17 00:00:00 2001 From: "timeless%mac.com" Date: Fri, 3 May 2002 14:50:46 +0000 Subject: [PATCH] Bug 87965 Can't expand chrome/*.jar files on ARM patch by jeroen.dobbelaere@acunia.com r=dveditz sr=brendan git-svn-id: svn://10.0.0.236/trunk@120697 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/libjar/nsZipArchive.cpp | 24 ++++++++++++++++-------- mozilla/modules/libjar/zipstruct.h | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/mozilla/modules/libjar/nsZipArchive.cpp b/mozilla/modules/libjar/nsZipArchive.cpp index 1295e9859e9..973ac2e5616 100644 --- a/mozilla/modules/libjar/nsZipArchive.cpp +++ b/mozilla/modules/libjar/nsZipArchive.cpp @@ -22,6 +22,7 @@ * Daniel Veditz * Samir Gehani * Mitch Stoltz + * Jeroen Dobbelaere */ /* @@ -909,7 +910,7 @@ PRInt32 nsZipArchive::BuildFileList() PRUint32 endsig; PRBool bEndsigFound = PR_FALSE; - for (endp -= sizeof(ZipEnd); endp >= buf; endp--) + for (endp -= ZIPEND_SIZE; endp >= buf; endp--) { endsig = xtolong(endp); if (endsig == ENDSIG) @@ -937,7 +938,7 @@ PRInt32 nsZipArchive::BuildFileList() status = ZIP_ERR_CORRUPT; //-- backward read must overlap ZipEnd length - pos += sizeof(ZipEnd); + pos += ZIPEND_SIZE; } /* while looking for end signature */ @@ -950,7 +951,7 @@ PRInt32 nsZipArchive::BuildFileList() //-- we think we found the central directory, read in the first chunk pos = 0; bufsize = PR_Read( mFd, &buf, sizeof(buf) ); - if (bufsize < (PRInt32)(sizeof(ZipCentral) + sizeof(ZipEnd))) + if (bufsize < (PRInt32)(ZIPCENTRAL_SIZE + ZIPEND_SIZE)) { // We know we read the end sig and got pointed at the central // directory--there should be at least this much @@ -1014,7 +1015,7 @@ PRInt32 nsZipArchive::BuildFileList() item->time = xtoint( central->time ); item->date = xtoint( central->date ); - pos += sizeof(ZipCentral); + pos += ZIPCENTRAL_SIZE; //------------------------------------------------------- // get the item name @@ -1069,7 +1070,7 @@ PRInt32 nsZipArchive::BuildFileList() // set up to process the next item at the top of loop //------------------------------------------------------- leftover = (PRUint32)(bufsize - pos); - if ( leftover < (extralen + commentlen + sizeof(ZipCentral)) ) + if ( leftover < (extralen + commentlen + ZIPCENTRAL_SIZE) ) { //-- not enough data left to process at top of loop. //-- move leftover and read more @@ -1090,13 +1091,20 @@ PRInt32 nsZipArchive::BuildFileList() } //-- make sure we've read enough - if ( (PRUint32)bufsize < pos + sizeof(ZipCentral) ) + if ( (PRUint32)bufsize < pos + ZIPCENTRAL_SIZE ) { status = ZIP_ERR_CORRUPT; break; } } /* while reading central directory records */ +#if defined(DEBUG) + if (status != ZIP_OK) { + const char* msgs[] = { "ZIP_OK", "ZIP_ERR_GENERAL", "ZIP_ERR_MEMORY", "ZIP_ERR_DISK", "ZIP_ERR_CORRUPT", "ZIP_ERR_PARAM", "ZIP_ERR_FNF", "ZIP_ERR_UNSUPPORTED", "ZIP_ERR_SMALLBUF", "UNKNOWN" }; + printf("nsZipArchive::BuildFileList status = %d '%s'\n", status, msgs[(status <= 0 && status >= -8) ? -status : 9]); + } +#endif + return status; } @@ -1157,14 +1165,14 @@ PRInt32 nsZipArchive::SeekToItem(const nsZipItem* aItem) return ZIP_ERR_CORRUPT; ZipLocal Local; - if ( PR_Read(mFd, (char*)&Local, sizeof(ZipLocal)) != (READTYPE)sizeof(ZipLocal) + if ( PR_Read(mFd, (char*)&Local, ZIPLOCAL_SIZE) != (READTYPE) ZIPLOCAL_SIZE || xtolong( Local.signature ) != LOCALSIG ) { //-- read error or local header not found return ZIP_ERR_CORRUPT; } - ((nsZipItem*)aItem)->offset += sizeof(Local) + + ((nsZipItem*)aItem)->offset += ZIPLOCAL_SIZE + xtoint( Local.filename_len ) + xtoint( Local.extrafield_len ); ((nsZipItem*)aItem)->flags |= ZIFLAG_DATAOFFSET; diff --git a/mozilla/modules/libjar/zipstruct.h b/mozilla/modules/libjar/zipstruct.h index d18ed68814a..518693b518b 100644 --- a/mozilla/modules/libjar/zipstruct.h +++ b/mozilla/modules/libjar/zipstruct.h @@ -20,6 +20,7 @@ * * Contributor(s): * Daniel Veditz + * Jeroen Dobbelaere */ #ifndef _zipstruct_h @@ -47,6 +48,13 @@ typedef struct ZipLocal_ unsigned char extrafield_len [2]; } ZipLocal; +/* + * 'sizeof(struct XXX)' includes padding on ARM (see bug 87965) + * As the internals of a jar/zip file must not depend on the target + * architecture (i386, ppc, ARM, ...), use a fixed value instead. + */ +#define ZIPLOCAL_SIZE (4+2+2+2+2+2+4+4+4+2+2) + typedef struct ZipCentral_ { unsigned char signature [4]; @@ -68,6 +76,13 @@ typedef struct ZipCentral_ unsigned char localhdr_offset [4]; } ZipCentral; +/* + * 'sizeof(struct XXX)' includes padding on ARM (see bug 87965) + * As the internals of a jar/zip file must not depend on the target + * architecture (i386, ppc, ARM, ...), use a fixed value instead. + */ +#define ZIPCENTRAL_SIZE (4+2+2+2+2+2+2+4+4+4+2+2+2+2+2+4+4) + typedef struct ZipEnd_ { unsigned char signature [4]; @@ -80,6 +95,13 @@ typedef struct ZipEnd_ unsigned char commentfield_len [2]; } ZipEnd; +/* + * 'sizeof(struct XXX)' includes padding on ARM (see bug 87965) + * As the internals of a jar/zip file must not depend on the target + * architecture (i386, ppc, ARM, ...), use a fixed value instead. + */ +#define ZIPEND_SIZE (4+2+2+2+2+4+4+2) + /* signatures */ #define LOCALSIG 0x04034B50l #define CENTRALSIG 0x02014B50l