** If aBlob is not NULL, then it is a pointer to a buffer (nBlob bytes in ** size) containing an entire zip archive image. Or, if aBlob is NULL, ** then pFile is a file-handle open on a zip file. In either case, this ** function creates a ZipfileEntry object based on the zip archive entry ** for which the CDS record is at offset iOff. ** ** If successful, SQLITE_OK is returned and (*ppEntry) set t
| 6672 | ** final value of (*ppEntry) undefined. |
| 6673 | */ |
| 6674 | static int zipfileGetEntry( |
| 6675 | ZipfileTab *pTab, /* Store any error message here */ |
| 6676 | const u8 *aBlob, /* Pointer to in-memory file image */ |
| 6677 | int nBlob, /* Size of aBlob[] in bytes */ |
| 6678 | FILE *pFile, /* If aBlob==0, read from this file */ |
| 6679 | i64 iOff, /* Offset of CDS record */ |
| 6680 | ZipfileEntry **ppEntry /* OUT: Pointer to new object */ |
| 6681 | ){ |
| 6682 | u8 *aRead; |
| 6683 | char **pzErr = &pTab->base.zErrMsg; |
| 6684 | int rc = SQLITE_OK; |
| 6685 | |
| 6686 | if( aBlob==0 ){ |
| 6687 | aRead = pTab->aBuffer; |
| 6688 | rc = zipfileReadData(pFile, aRead, ZIPFILE_CDS_FIXED_SZ, iOff, pzErr); |
| 6689 | }else{ |
| 6690 | aRead = (u8*)&aBlob[iOff]; |
| 6691 | } |
| 6692 | |
| 6693 | if( rc==SQLITE_OK ){ |
| 6694 | sqlite3_int64 nAlloc; |
| 6695 | ZipfileEntry *pNew; |
| 6696 | |
| 6697 | int nFile = zipfileGetU16(&aRead[ZIPFILE_CDS_NFILE_OFF]); |
| 6698 | int nExtra = zipfileGetU16(&aRead[ZIPFILE_CDS_NFILE_OFF+2]); |
| 6699 | nExtra += zipfileGetU16(&aRead[ZIPFILE_CDS_NFILE_OFF+4]); |
| 6700 | |
| 6701 | nAlloc = sizeof(ZipfileEntry) + nExtra; |
| 6702 | if( aBlob ){ |
| 6703 | nAlloc += zipfileGetU32(&aRead[ZIPFILE_CDS_SZCOMPRESSED_OFF]); |
| 6704 | } |
| 6705 | |
| 6706 | pNew = (ZipfileEntry*)sqlite3_malloc64(nAlloc); |
| 6707 | if( pNew==0 ){ |
| 6708 | rc = SQLITE_NOMEM; |
| 6709 | }else{ |
| 6710 | memset(pNew, 0, sizeof(ZipfileEntry)); |
| 6711 | rc = zipfileReadCDS(aRead, &pNew->cds); |
| 6712 | if( rc!=SQLITE_OK ){ |
| 6713 | *pzErr = sqlite3_mprintf("failed to read CDS at offset %lld", iOff); |
| 6714 | }else if( aBlob==0 ){ |
| 6715 | rc = zipfileReadData( |
| 6716 | pFile, aRead, nExtra+nFile, iOff+ZIPFILE_CDS_FIXED_SZ, pzErr |
| 6717 | ); |
| 6718 | }else{ |
| 6719 | aRead = (u8*)&aBlob[iOff + ZIPFILE_CDS_FIXED_SZ]; |
| 6720 | } |
| 6721 | } |
| 6722 | |
| 6723 | if( rc==SQLITE_OK ){ |
| 6724 | u32 *pt = &pNew->mUnixTime; |
| 6725 | pNew->cds.zFile = sqlite3_mprintf("%.*s", nFile, aRead); |
| 6726 | pNew->aExtra = (u8*)&pNew[1]; |
| 6727 | memcpy(pNew->aExtra, &aRead[nFile], nExtra); |
| 6728 | if( pNew->cds.zFile==0 ){ |
| 6729 | rc = SQLITE_NOMEM; |
| 6730 | }else if( 0==zipfileScanExtra(&aRead[nFile], pNew->cds.nExtra, pt) ){ |
| 6731 | pNew->mUnixTime = zipfileMtime(&pNew->cds); |
no test coverage detected