Use explicitly sized types in zipalign/ziptime
getLongLE would return a 64-bit number with the upper 32-bits set when decoding a 32-bit number with the top bit set. Per the zip file format, it was only expected to return a 32-bit number. Use explicitly sized types so that we use the proper sizes and don't do any implicit extensions. Change-Id: I5a4304dc99ce5f8f17284d4ca3094ae115207a1e
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
@@ -56,7 +57,7 @@ status_t ZipEntry::initFromCDE(FILE* fp)
|
||||
/* using the info in the CDE, go load up the LFH */
|
||||
posn = ftell(fp);
|
||||
if (fseek(fp, mCDE.mLocalHeaderRelOffset, SEEK_SET) != 0) {
|
||||
ALOGD("local header seek failed (%ld)\n",
|
||||
ALOGD("local header seek failed (%" PRIu32 ")\n",
|
||||
mCDE.mLocalHeaderRelOffset);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
@@ -123,12 +124,12 @@ void ZipEntry::initNew(const char* fileName, const char* comment)
|
||||
mCDE.mExternalAttrs = 0x81b60020; // matches what WinZip does
|
||||
|
||||
if (mCDE.mFileNameLength > 0) {
|
||||
mCDE.mFileName = new unsigned char[mCDE.mFileNameLength+1];
|
||||
mCDE.mFileName = new uint8_t[mCDE.mFileNameLength+1];
|
||||
strcpy((char*) mCDE.mFileName, fileName);
|
||||
}
|
||||
if (mCDE.mFileCommentLength > 0) {
|
||||
/* TODO: stop assuming null-terminated ASCII here? */
|
||||
mCDE.mFileComment = new unsigned char[mCDE.mFileCommentLength+1];
|
||||
mCDE.mFileComment = new uint8_t[mCDE.mFileCommentLength+1];
|
||||
strcpy((char*) mCDE.mFileComment, comment);
|
||||
}
|
||||
|
||||
@@ -150,20 +151,20 @@ status_t ZipEntry::initFromExternal(const ZipFile* pZipFile,
|
||||
memcpy(&mCDE, &pEntry->mCDE, sizeof(mCDE));
|
||||
|
||||
if (mCDE.mFileNameLength > 0) {
|
||||
mCDE.mFileName = new unsigned char[mCDE.mFileNameLength+1];
|
||||
mCDE.mFileName = new uint8_t[mCDE.mFileNameLength+1];
|
||||
if (mCDE.mFileName == NULL)
|
||||
return NO_MEMORY;
|
||||
strcpy((char*) mCDE.mFileName, (char*)pEntry->mCDE.mFileName);
|
||||
}
|
||||
if (mCDE.mFileCommentLength > 0) {
|
||||
mCDE.mFileComment = new unsigned char[mCDE.mFileCommentLength+1];
|
||||
mCDE.mFileComment = new uint8_t[mCDE.mFileCommentLength+1];
|
||||
if (mCDE.mFileComment == NULL)
|
||||
return NO_MEMORY;
|
||||
strcpy((char*) mCDE.mFileComment, (char*)pEntry->mCDE.mFileComment);
|
||||
}
|
||||
if (mCDE.mExtraFieldLength > 0) {
|
||||
/* we null-terminate this, though it may not be a string */
|
||||
mCDE.mExtraField = new unsigned char[mCDE.mExtraFieldLength+1];
|
||||
mCDE.mExtraField = new uint8_t[mCDE.mExtraFieldLength+1];
|
||||
if (mCDE.mExtraField == NULL)
|
||||
return NO_MEMORY;
|
||||
memcpy(mCDE.mExtraField, pEntry->mCDE.mExtraField,
|
||||
@@ -180,7 +181,7 @@ status_t ZipEntry::initFromExternal(const ZipFile* pZipFile,
|
||||
assert(mLFH.mExtraField == NULL);
|
||||
mLFH.mExtraFieldLength = pEntry->mLFH.mExtraFieldLength;
|
||||
if (mLFH.mExtraFieldLength > 0) {
|
||||
mLFH.mExtraField = new unsigned char[mLFH.mExtraFieldLength+1];
|
||||
mLFH.mExtraField = new uint8_t[mLFH.mExtraFieldLength+1];
|
||||
if (mLFH.mExtraField == NULL)
|
||||
return NO_MEMORY;
|
||||
memcpy(mLFH.mExtraField, pEntry->mLFH.mExtraField,
|
||||
@@ -205,9 +206,9 @@ status_t ZipEntry::addPadding(int padding)
|
||||
|
||||
if (mLFH.mExtraFieldLength > 0) {
|
||||
/* extend existing field */
|
||||
unsigned char* newExtra;
|
||||
uint8_t* newExtra;
|
||||
|
||||
newExtra = new unsigned char[mLFH.mExtraFieldLength + padding];
|
||||
newExtra = new uint8_t[mLFH.mExtraFieldLength + padding];
|
||||
if (newExtra == NULL)
|
||||
return NO_MEMORY;
|
||||
memset(newExtra + mLFH.mExtraFieldLength, 0, padding);
|
||||
@@ -218,7 +219,7 @@ status_t ZipEntry::addPadding(int padding)
|
||||
mLFH.mExtraFieldLength += padding;
|
||||
} else {
|
||||
/* create new field */
|
||||
mLFH.mExtraField = new unsigned char[padding];
|
||||
mLFH.mExtraField = new uint8_t[padding];
|
||||
memset(mLFH.mExtraField, 0, padding);
|
||||
mLFH.mExtraFieldLength = padding;
|
||||
}
|
||||
@@ -246,7 +247,7 @@ void ZipEntry::copyCDEtoLFH(void)
|
||||
|
||||
delete[] mLFH.mFileName;
|
||||
if (mLFH.mFileNameLength > 0) {
|
||||
mLFH.mFileName = new unsigned char[mLFH.mFileNameLength+1];
|
||||
mLFH.mFileName = new uint8_t[mLFH.mFileNameLength+1];
|
||||
strcpy((char*) mLFH.mFileName, (const char*) mCDE.mFileName);
|
||||
} else {
|
||||
mLFH.mFileName = NULL;
|
||||
@@ -256,7 +257,7 @@ void ZipEntry::copyCDEtoLFH(void)
|
||||
/*
|
||||
* Set some information about a file after we add it.
|
||||
*/
|
||||
void ZipEntry::setDataInfo(long uncompLen, long compLen, unsigned long crc32,
|
||||
void ZipEntry::setDataInfo(long uncompLen, long compLen, uint32_t crc32,
|
||||
int compressionMethod)
|
||||
{
|
||||
mCDE.mCompressionMethod = compressionMethod;
|
||||
@@ -360,7 +361,7 @@ void ZipEntry::setModWhen(time_t when)
|
||||
struct tm tmResult;
|
||||
#endif
|
||||
time_t even;
|
||||
unsigned short zdate, ztime;
|
||||
uint16_t zdate, ztime;
|
||||
|
||||
struct tm* ptm;
|
||||
|
||||
@@ -402,7 +403,7 @@ void ZipEntry::setModWhen(time_t when)
|
||||
status_t ZipEntry::LocalFileHeader::read(FILE* fp)
|
||||
{
|
||||
status_t result = NO_ERROR;
|
||||
unsigned char buf[kLFHLen];
|
||||
uint8_t buf[kLFHLen];
|
||||
|
||||
assert(mFileName == NULL);
|
||||
assert(mExtraField == NULL);
|
||||
@@ -433,7 +434,7 @@ status_t ZipEntry::LocalFileHeader::read(FILE* fp)
|
||||
|
||||
/* grab filename */
|
||||
if (mFileNameLength != 0) {
|
||||
mFileName = new unsigned char[mFileNameLength+1];
|
||||
mFileName = new uint8_t[mFileNameLength+1];
|
||||
if (mFileName == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
@@ -447,7 +448,7 @@ status_t ZipEntry::LocalFileHeader::read(FILE* fp)
|
||||
|
||||
/* grab extra field */
|
||||
if (mExtraFieldLength != 0) {
|
||||
mExtraField = new unsigned char[mExtraFieldLength+1];
|
||||
mExtraField = new uint8_t[mExtraFieldLength+1];
|
||||
if (mExtraField == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
@@ -468,7 +469,7 @@ bail:
|
||||
*/
|
||||
status_t ZipEntry::LocalFileHeader::write(FILE* fp)
|
||||
{
|
||||
unsigned char buf[kLFHLen];
|
||||
uint8_t buf[kLFHLen];
|
||||
|
||||
ZipEntry::putLongLE(&buf[0x00], kSignature);
|
||||
ZipEntry::putShortLE(&buf[0x04], mVersionToExtract);
|
||||
@@ -507,13 +508,13 @@ status_t ZipEntry::LocalFileHeader::write(FILE* fp)
|
||||
void ZipEntry::LocalFileHeader::dump(void) const
|
||||
{
|
||||
ALOGD(" LocalFileHeader contents:\n");
|
||||
ALOGD(" versToExt=%u gpBits=0x%04x compression=%u\n",
|
||||
ALOGD(" versToExt=%" PRIu16 " gpBits=0x%04" PRIx16 " compression=%" PRIu16 "\n",
|
||||
mVersionToExtract, mGPBitFlag, mCompressionMethod);
|
||||
ALOGD(" modTime=0x%04x modDate=0x%04x crc32=0x%08lx\n",
|
||||
ALOGD(" modTime=0x%04" PRIx16 " modDate=0x%04" PRIx16 " crc32=0x%08" PRIx32 "\n",
|
||||
mLastModFileTime, mLastModFileDate, mCRC32);
|
||||
ALOGD(" compressedSize=%lu uncompressedSize=%lu\n",
|
||||
ALOGD(" compressedSize=%" PRIu32 " uncompressedSize=%" PRIu32 "\n",
|
||||
mCompressedSize, mUncompressedSize);
|
||||
ALOGD(" filenameLen=%u extraLen=%u\n",
|
||||
ALOGD(" filenameLen=%" PRIu16 " extraLen=%" PRIu16 "\n",
|
||||
mFileNameLength, mExtraFieldLength);
|
||||
if (mFileName != NULL)
|
||||
ALOGD(" filename: '%s'\n", mFileName);
|
||||
@@ -536,7 +537,7 @@ void ZipEntry::LocalFileHeader::dump(void) const
|
||||
status_t ZipEntry::CentralDirEntry::read(FILE* fp)
|
||||
{
|
||||
status_t result = NO_ERROR;
|
||||
unsigned char buf[kCDELen];
|
||||
uint8_t buf[kCDELen];
|
||||
|
||||
/* no re-use */
|
||||
assert(mFileName == NULL);
|
||||
@@ -575,7 +576,7 @@ status_t ZipEntry::CentralDirEntry::read(FILE* fp)
|
||||
|
||||
/* grab filename */
|
||||
if (mFileNameLength != 0) {
|
||||
mFileName = new unsigned char[mFileNameLength+1];
|
||||
mFileName = new uint8_t[mFileNameLength+1];
|
||||
if (mFileName == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
@@ -589,7 +590,7 @@ status_t ZipEntry::CentralDirEntry::read(FILE* fp)
|
||||
|
||||
/* read "extra field" */
|
||||
if (mExtraFieldLength != 0) {
|
||||
mExtraField = new unsigned char[mExtraFieldLength+1];
|
||||
mExtraField = new uint8_t[mExtraFieldLength+1];
|
||||
if (mExtraField == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
@@ -604,7 +605,7 @@ status_t ZipEntry::CentralDirEntry::read(FILE* fp)
|
||||
|
||||
/* grab comment, if any */
|
||||
if (mFileCommentLength != 0) {
|
||||
mFileComment = new unsigned char[mFileCommentLength+1];
|
||||
mFileComment = new uint8_t[mFileCommentLength+1];
|
||||
if (mFileComment == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
@@ -626,7 +627,7 @@ bail:
|
||||
*/
|
||||
status_t ZipEntry::CentralDirEntry::write(FILE* fp)
|
||||
{
|
||||
unsigned char buf[kCDELen];
|
||||
uint8_t buf[kCDELen];
|
||||
|
||||
ZipEntry::putLongLE(&buf[0x00], kSignature);
|
||||
ZipEntry::putShortLE(&buf[0x04], mVersionMadeBy);
|
||||
@@ -676,15 +677,15 @@ status_t ZipEntry::CentralDirEntry::write(FILE* fp)
|
||||
void ZipEntry::CentralDirEntry::dump(void) const
|
||||
{
|
||||
ALOGD(" CentralDirEntry contents:\n");
|
||||
ALOGD(" versMadeBy=%u versToExt=%u gpBits=0x%04x compression=%u\n",
|
||||
ALOGD(" versMadeBy=%" PRIu16 " versToExt=%" PRIu16 " gpBits=0x%04" PRIx16 " compression=%" PRIu16 "\n",
|
||||
mVersionMadeBy, mVersionToExtract, mGPBitFlag, mCompressionMethod);
|
||||
ALOGD(" modTime=0x%04x modDate=0x%04x crc32=0x%08lx\n",
|
||||
ALOGD(" modTime=0x%04" PRIx16 " modDate=0x%04" PRIx16 " crc32=0x%08" PRIx32 "\n",
|
||||
mLastModFileTime, mLastModFileDate, mCRC32);
|
||||
ALOGD(" compressedSize=%lu uncompressedSize=%lu\n",
|
||||
ALOGD(" compressedSize=%" PRIu32 " uncompressedSize=%" PRIu32 "\n",
|
||||
mCompressedSize, mUncompressedSize);
|
||||
ALOGD(" filenameLen=%u extraLen=%u commentLen=%u\n",
|
||||
ALOGD(" filenameLen=%" PRIu16 " extraLen=%" PRIu16 " commentLen=%" PRIu16 "\n",
|
||||
mFileNameLength, mExtraFieldLength, mFileCommentLength);
|
||||
ALOGD(" diskNumStart=%u intAttr=0x%04x extAttr=0x%08lx relOffset=%lu\n",
|
||||
ALOGD(" diskNumStart=%" PRIu16 " intAttr=0x%04" PRIx16 " extAttr=0x%08" PRIx32 " relOffset=%" PRIu32 "\n",
|
||||
mDiskNumberStart, mInternalAttrs, mExternalAttrs,
|
||||
mLocalHeaderRelOffset);
|
||||
|
||||
|
Reference in New Issue
Block a user