Merge "Let findSupportedAbi and hasRenderscriptBitcode scan only relevant files"

This commit is contained in:
Yusuke Sato
2015-08-05 17:46:18 +00:00
committed by Gerrit Code Review
3 changed files with 14 additions and 13 deletions

View File

@@ -48,7 +48,6 @@
#define LIB_SUFFIX_LEN (sizeof(LIB_SUFFIX) - 1) #define LIB_SUFFIX_LEN (sizeof(LIB_SUFFIX) - 1)
#define RS_BITCODE_SUFFIX ".bc" #define RS_BITCODE_SUFFIX ".bc"
#define RS_BITCODE_SUFFIX_LEN (sizeof(RS_BITCODE_SUFFIX) -1)
#define GDBSERVER "gdbserver" #define GDBSERVER "gdbserver"
#define GDBSERVER_LEN (sizeof(GDBSERVER) - 1) #define GDBSERVER_LEN (sizeof(GDBSERVER) - 1)
@@ -322,7 +321,8 @@ private:
public: public:
static NativeLibrariesIterator* create(ZipFileRO* zipFile) { static NativeLibrariesIterator* create(ZipFileRO* zipFile) {
void* cookie = NULL; void* cookie = NULL;
if (!zipFile->startIteration(&cookie)) { // Do not specify a suffix to find both .so files and gdbserver.
if (!zipFile->startIteration(&cookie, APK_LIB, NULL /* suffix */)) {
return NULL; return NULL;
} }
@@ -337,11 +337,6 @@ public:
continue; continue;
} }
// Make sure we're in the lib directory of the ZIP.
if (strncmp(fileName, APK_LIB, APK_LIB_LEN)) {
continue;
}
// Make sure the filename is at least to the minimum library name size. // Make sure the filename is at least to the minimum library name size.
const size_t fileNameLen = strlen(fileName); const size_t fileNameLen = strlen(fileName);
static const size_t minLength = APK_LIB_LEN + 2 + LIB_PREFIX_LEN + 1 + LIB_SUFFIX_LEN; static const size_t minLength = APK_LIB_LEN + 2 + LIB_PREFIX_LEN + 1 + LIB_SUFFIX_LEN;
@@ -529,7 +524,7 @@ com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode(JNIEnv *
jlong apkHandle) { jlong apkHandle) {
ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle); ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle);
void* cookie = NULL; void* cookie = NULL;
if (!zipFile->startIteration(&cookie)) { if (!zipFile->startIteration(&cookie, NULL /* prefix */, RS_BITCODE_SUFFIX)) {
return APK_SCAN_ERROR; return APK_SCAN_ERROR;
} }
@@ -539,12 +534,9 @@ com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode(JNIEnv *
if (zipFile->getEntryFileName(next, fileName, sizeof(fileName))) { if (zipFile->getEntryFileName(next, fileName, sizeof(fileName))) {
continue; continue;
} }
const size_t fileNameLen = strlen(fileName);
const char* lastSlash = strrchr(fileName, '/'); const char* lastSlash = strrchr(fileName, '/');
const char* baseName = (lastSlash == NULL) ? fileName : fileName + 1; const char* baseName = (lastSlash == NULL) ? fileName : fileName + 1;
if (!strncmp(fileName + fileNameLen - RS_BITCODE_SUFFIX_LEN, RS_BITCODE_SUFFIX, if (isFilenameSafe(baseName)) {
RS_BITCODE_SUFFIX_LEN) && isFilenameSafe(baseName)) {
zipFile->endIteration(cookie); zipFile->endIteration(cookie);
return BITCODE_PRESENT; return BITCODE_PRESENT;
} }

View File

@@ -91,6 +91,7 @@ public:
* a matching call to endIteration with the same cookie. * a matching call to endIteration with the same cookie.
*/ */
bool startIteration(void** cookie); bool startIteration(void** cookie);
bool startIteration(void** cookie, const char* prefix, const char* suffix);
/** /**
* Return the next entry in iteration order, or NULL if there are no more * Return the next entry in iteration order, or NULL if there are no more

View File

@@ -126,10 +126,18 @@ bool ZipFileRO::getEntryInfo(ZipEntryRO entry, uint16_t* pMethod,
} }
bool ZipFileRO::startIteration(void** cookie) bool ZipFileRO::startIteration(void** cookie)
{
return startIteration(cookie, NULL, NULL);
}
bool ZipFileRO::startIteration(void** cookie, const char* prefix, const char* suffix)
{ {
_ZipEntryRO* ze = new _ZipEntryRO; _ZipEntryRO* ze = new _ZipEntryRO;
ZipString pe(prefix ? prefix : "");
ZipString se(suffix ? suffix : "");
int32_t error = StartIteration(mHandle, &(ze->cookie), int32_t error = StartIteration(mHandle, &(ze->cookie),
NULL /* prefix */, NULL /* suffix */); prefix ? &pe : NULL,
suffix ? &se : NULL);
if (error) { if (error) {
ALOGW("Could not start iteration over %s: %s", mFileName, ErrorCodeString(error)); ALOGW("Could not start iteration over %s: %s", mFileName, ErrorCodeString(error));
delete ze; delete ze;