From 83f4c0994fd34f9b35eeb2c14908d9e6c2e15930 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Thu, 4 Mar 2010 15:21:59 -0800 Subject: [PATCH] Fix potential aapt crash when processing overlay. If an overlay has a type of resources that's not defined in the main res pool, then aapt would crash. This dynamically create new ResourceTypeSet when needed when processing the overlays Change-Id: I67bc3622281bde73cf42f37a0983798d3f658ce2 --- tools/aapt/Resource.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp index ea021d82e4da..b7580b33c723 100644 --- a/tools/aapt/Resource.cpp +++ b/tools/aapt/Resource.cpp @@ -447,7 +447,7 @@ static void checkForIds(const String8& path, ResXMLParser& parser) static bool applyFileOverlay(Bundle *bundle, const sp& assets, - const sp& baseSet, + sp *baseSet, const char *resType) { if (bundle->getVerbose()) { @@ -475,13 +475,16 @@ static bool applyFileOverlay(Bundle *bundle, if (bundle->getVerbose()) { printf("trying overlaySet Key=%s\n",overlaySet->keyAt(overlayIndex).string()); } - size_t baseIndex = baseSet->indexOfKey(overlaySet->keyAt(overlayIndex)); + size_t baseIndex = UNKNOWN_ERROR; + if (baseSet->get() != NULL) { + baseIndex = (*baseSet)->indexOfKey(overlaySet->keyAt(overlayIndex)); + } if (baseIndex < UNKNOWN_ERROR) { // look for same flavor. For a given file (strings.xml, for example) // there may be a locale specific or other flavors - we want to match // the same flavor. sp overlayGroup = overlaySet->valueAt(overlayIndex); - sp baseGroup = baseSet->valueAt(baseIndex); + sp baseGroup = (*baseSet)->valueAt(baseIndex); DefaultKeyedVector > overlayFiles = overlayGroup->getFiles(); @@ -520,8 +523,12 @@ static bool applyFileOverlay(Bundle *bundle, assets->addGroupEntry(overlayFiles.keyAt(overlayGroupIndex)); } } else { + if (baseSet->get() == NULL) { + *baseSet = new ResourceTypeSet(); + assets->getResources()->add(String8(resType), *baseSet); + } // this group doesn't exist (a file that's only in the overlay) - baseSet->add(overlaySet->keyAt(overlayIndex), + (*baseSet)->add(overlaySet->keyAt(overlayIndex), overlaySet->valueAt(overlayIndex)); // make sure all flavors are defined in the resources. sp overlayGroup = overlaySet->valueAt(overlayIndex); @@ -751,13 +758,13 @@ status_t buildResources(Bundle* bundle, const sp& assets) current = current->getOverlay(); } // apply the overlay files to the base set - if (!applyFileOverlay(bundle, assets, drawables, "drawable") || - !applyFileOverlay(bundle, assets, layouts, "layout") || - !applyFileOverlay(bundle, assets, anims, "anim") || - !applyFileOverlay(bundle, assets, xmls, "xml") || - !applyFileOverlay(bundle, assets, raws, "raw") || - !applyFileOverlay(bundle, assets, colors, "color") || - !applyFileOverlay(bundle, assets, menus, "menu")) { + if (!applyFileOverlay(bundle, assets, &drawables, "drawable") || + !applyFileOverlay(bundle, assets, &layouts, "layout") || + !applyFileOverlay(bundle, assets, &anims, "anim") || + !applyFileOverlay(bundle, assets, &xmls, "xml") || + !applyFileOverlay(bundle, assets, &raws, "raw") || + !applyFileOverlay(bundle, assets, &colors, "color") || + !applyFileOverlay(bundle, assets, &menus, "menu")) { return UNKNOWN_ERROR; } -- 2.11.0