Merge "Frameworks/base: Fix more aapt issues"

This commit is contained in:
Andreas Gampe
2014-10-02 06:58:38 +00:00
committed by Gerrit Code Review
4 changed files with 51 additions and 30 deletions

View File

@ -192,7 +192,7 @@ inline bool isNumber(const String8& string) {
void AaptLocaleValue::setLanguage(const char* languageChars) {
size_t i = 0;
while ((*languageChars) != '\0') {
while ((*languageChars) != '\0' && i < sizeof(language)/sizeof(language[0])) {
language[i++] = tolower(*languageChars);
languageChars++;
}
@ -200,7 +200,7 @@ void AaptLocaleValue::setLanguage(const char* languageChars) {
void AaptLocaleValue::setRegion(const char* regionChars) {
size_t i = 0;
while ((*regionChars) != '\0') {
while ((*regionChars) != '\0' && i < sizeof(region)/sizeof(region[0])) {
region[i++] = toupper(*regionChars);
regionChars++;
}
@ -208,7 +208,7 @@ void AaptLocaleValue::setRegion(const char* regionChars) {
void AaptLocaleValue::setScript(const char* scriptChars) {
size_t i = 0;
while ((*scriptChars) != '\0') {
while ((*scriptChars) != '\0' && i < sizeof(script)/sizeof(script[0])) {
if (i == 0) {
script[i++] = toupper(*scriptChars);
} else {
@ -220,7 +220,7 @@ void AaptLocaleValue::setScript(const char* scriptChars) {
void AaptLocaleValue::setVariant(const char* variantChars) {
size_t i = 0;
while ((*variantChars) != '\0') {
while ((*variantChars) != '\0' && i < sizeof(variant)/sizeof(variant[0])) {
variant[i++] = *variantChars;
variantChars++;
}

View File

@ -196,11 +196,16 @@ int doList(Bundle* bundle)
goto bail;
}
const ResTable& res = assets.getResources(false);
#ifndef HAVE_ANDROID_OS
printf("\nResource table:\n");
res.print(false);
#ifdef HAVE_ANDROID_OS
static const bool kHaveAndroidOs = true;
#else
static const bool kHaveAndroidOs = false;
#endif
const ResTable& res = assets.getResources(false);
if (!kHaveAndroidOs) {
printf("\nResource table:\n");
res.print(false);
}
Asset* manifestAsset = assets.openNonAsset("AndroidManifest.xml",
Asset::ACCESS_BUFFER);

View File

@ -1095,6 +1095,41 @@ static void write_png(const char* imageName,
}
}
static bool read_png_protected(png_structp read_ptr, String8& printableName, png_infop read_info,
const sp<AaptFile>& file, FILE* fp, image_info* imageInfo) {
if (setjmp(png_jmpbuf(read_ptr))) {
return false;
}
png_init_io(read_ptr, fp);
read_png(printableName.string(), read_ptr, read_info, imageInfo);
const size_t nameLen = file->getPath().length();
if (nameLen > 6) {
const char* name = file->getPath().string();
if (name[nameLen-5] == '9' && name[nameLen-6] == '.') {
if (do_9patch(printableName.string(), imageInfo) != NO_ERROR) {
return false;
}
}
}
return true;
}
static bool write_png_protected(png_structp write_ptr, String8& printableName, png_infop write_info,
image_info* imageInfo, const Bundle* bundle) {
if (setjmp(png_jmpbuf(write_ptr))) {
return false;
}
write_png(printableName.string(), write_ptr, write_info, *imageInfo,
bundle->getGrayscaleTolerance());
return true;
}
status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& /* assets */,
const sp<AaptFile>& file, String8* /* outNewLeafName */)
{
@ -1126,8 +1161,6 @@ status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& /* assets *
status_t error = UNKNOWN_ERROR;
const size_t nameLen = file->getPath().length();
fp = fopen(file->getSourceFile().string(), "rb");
if (fp == NULL) {
fprintf(stderr, "%s: ERROR: Unable to open PNG file\n", printableName.string());
@ -1145,23 +1178,10 @@ status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& /* assets *
goto bail;
}
if (setjmp(png_jmpbuf(read_ptr))) {
if (!read_png_protected(read_ptr, printableName, read_info, file, fp, &imageInfo)) {
goto bail;
}
png_init_io(read_ptr, fp);
read_png(printableName.string(), read_ptr, read_info, &imageInfo);
if (nameLen > 6) {
const char* name = file->getPath().string();
if (name[nameLen-5] == '9' && name[nameLen-6] == '.') {
if (do_9patch(printableName.string(), &imageInfo) != NO_ERROR) {
goto bail;
}
}
}
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, (png_error_ptr)NULL,
(png_error_ptr)NULL);
if (!write_ptr)
@ -1178,14 +1198,10 @@ status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& /* assets *
png_set_write_fn(write_ptr, (void*)file.get(),
png_write_aapt_file, png_flush_aapt_file);
if (setjmp(png_jmpbuf(write_ptr)))
{
if (!write_png_protected(write_ptr, printableName, write_info, &imageInfo, bundle)) {
goto bail;
}
write_png(printableName.string(), write_ptr, write_info, imageInfo,
bundle->getGrayscaleTolerance());
error = NO_ERROR;
if (bundle->getVerbose()) {

View File

@ -989,7 +989,7 @@ status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
for (size_t i=0; i<N; i++) {
const attribute_entry& e = mAttributes.itemAt(i);
if (e.ns.size() <= 0) continue;
bool nsIsPublic;
bool nsIsPublic = true;
String16 pkg(getNamespaceResourcePackage(String16(assets->getPackage()), e.ns, &nsIsPublic));
if (kIsDebug) {
printf("Elem %s %s=\"%s\": namespace(%s) %s ===> %s\n",