Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39b442cb authored by Dan Zimmerman's avatar Dan Zimmerman Committed by Calin Juravle
Browse files

[DexManager] Fix off-by-N error in DexManager when reporting dex loads

In this loop the continue statement skips over incrementing
dexPathIndex. In effect the classloader context that reported for a
given dex file may be incorrect (specifically in the situation when the
user loads a primary dex file and a secondary dex file in the same
ClassLoader)

Bug: 147089377
Test: atest com.android.server.pm.dex.DexManagerTests
Change-Id: I7d3df507787f758537625b702131a2f4f76190e6
parent 725c5406
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -229,6 +229,7 @@ public class DexManager {
                    // If the dex file is the primary apk (or a split) and not isUsedByOtherApps
                    // do not record it. This case does not bring any new usable information
                    // and can be safely skipped.
                    dexPathIndex++;
                    continue;
                }

+25 −0
Original line number Diff line number Diff line
@@ -159,6 +159,31 @@ public class DexManagerTests {
        assertHasDclInfo(mFooUser0, mFooUser0, fooSecondaries);
    }

    @Test
    public void testNotifyPrimaryAndSecondary() {
        List<String> dexFiles = mFooUser0.getBaseAndSplitDexPaths();
        List<String> secondaries = mFooUser0.getSecondaryDexPaths();
        int baseAndSplitCount = dexFiles.size();
        dexFiles.addAll(secondaries);

        notifyDexLoad(mFooUser0, dexFiles, mUser0);

        PackageUseInfo pui = getPackageUseInfo(mFooUser0);
        assertIsUsedByOtherApps(mFooUser0, pui, false);
        assertEquals(secondaries.size(), pui.getDexUseInfoMap().size());

        String[] allExpectedContexts = DexoptUtils.processContextForDexLoad(
                Arrays.asList(mFooUser0.mClassLoader),
                Arrays.asList(String.join(File.pathSeparator, dexFiles)));
        String[] secondaryExpectedContexts = Arrays.copyOfRange(allExpectedContexts,
                baseAndSplitCount, dexFiles.size());

        assertSecondaryUse(mFooUser0, pui, secondaries, /*isUsedByOtherApps*/false, mUser0,
                secondaryExpectedContexts);

        assertHasDclInfo(mFooUser0, mFooUser0, secondaries);
    }

    @Test
    public void testNotifySecondaryForeign() {
        // Foo loads bar secondary files.