CVE-2026-58937 AI-generated analysis
platform/frameworks/base, WindowManager / ActivityTaskManager task persistence (TaskPersister), plus android.os.BaseBundle/Bundle
Adds size limits to recent-task persistence in TaskPersister. On save, the total PersistableBundle size per task is capped at 2.5 MB and the serialized task XML at 5 MB. On restore, task XML files larger than 5 MB are deleted instead of parsed. Per the commit message, this prevents OutOfMemoryError crashes.
Root cause
TaskPersister serialized each recent task to a per-task XML file with no bound on its size. That XML includes the PersistableBundle persistent saved state of each persistable activity. restoreTasksForUserLocked read every task file back regardless of size. Per the commit message, many or very large task XML files caused OutOfMemoryError crashes while loading or saving. There was also no way to measure a PersistableBundle's size, because getSize() existed only on Bundle and not on BaseBundle.
How the fix works
- core/java/android/os/BaseBundle.java: adds a @hide getSize() that returns mParcelledData.dataSize() while the bundle is still parcelled, otherwise 0. core/java/android/os/Bundle.java: Bundle.getSize() becomes an @Override that delegates to super.getSize(). As a result, PersistableBundle also exposes getSize(), and TaskPersister calls it.
- services/core/java/com/android/server/wm/ActivityRecord.java: adds a static shouldSkipSavingToXml(r, bottomMostActivity), extracted from Task.saveActivityToXml. It returns true when persistableMode == PERSIST_ROOT_ONLY, or when !r.isPersistable(), or when (intent flags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS)) == FLAG_ACTIVITY_NEW_DOCUMENT and r is not the bottom-most activity. The mask is now parenthesized. In the old expression `flags & FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS`, Java precedence ORed RETAIN_IN_RECENTS into the result, so that term could never equal NEW_DOCUMENT.
- services/core/java/com/android/server/wm/Task.java: saveActivityToXml now calls shouldSkipSavingToXml(r, bottomMostActivity) instead of the inline condition. The parameter is renamed from first to bottomMostActivity.
- services/core/java/com/android/server/wm/TaskPersister.java: adds MAX_TASK_FILE_SIZE = 5 MiB and MAX_PERSISTABLE_BUNDLE_SIZE_PER_TASK = 2.5 MiB. In TaskWriteQueueItem, when task.inRecents and before saveToXml, it iterates task.forAllActivities and sums r.getPersistentSavedState().getSize(). Iteration stops at the first activity for which shouldSkipSavingToXml is true. If the total exceeds 2.5 MiB, it logs and returns without writing. After serialization, if data.length exceeds 5 MiB, it logs and returns without writing.
- services/core/java/com/android/server/wm/TaskPersister.java: restoreTasksForUserLocked checks taskFile.length() before it constructs RecentTaskFile. Files larger than 5 MiB are logged, deleted with taskFile.delete(), and skipped.
Completeness
- Both the write path (TaskWriteQueueItem) and the read path (restoreTasksForUserLocked) are bounded. Oversized files already on disk are deleted at the next restore, and the new save checks keep new ones from being written.
- BaseBundle.getSize() returns 0 when mParcelledData is null. BaseBundle.unparcel sets mParcelledData = null, so an unparcelled bundle reports 0. The 2.5 MiB pre-check therefore only counts bundles still in parcelled form. For other bundles, the 5 MiB check on the serialized byte array is the backstop.
- The bundle pre-check only sums the PersistableBundle persistent saved state. Other content serialized by Task.saveToXml / ActivityRecord.saveToXml is limited only by the post-serialization 5 MiB check, and the XML must be fully built in memory before that check runs.
- When persistence is dropped by either limit, the code returns without writing. The material does not show any removal of a previously written file for that task, so a stale, smaller file may remain.
- The limits are hard-coded constants with no configuration. Task images (IMAGES_DIRNAME) are not covered by this change.
Behavior changes
- If the parcelled PersistableBundle data of a task's persistable activities totals more than 2.5 MiB, the task's current state is no longer written. The log shows Slog.e 'Exceeded max persistable bundle size per task ... Dropping persistence.'
- Serialized task XML larger than 5 MiB is not written. The log shows Slog.w 'Task file size exceeds limit'.
- On restore, task files larger than 5 MiB are deleted from disk and skipped. The log shows Slog.e 'Restore task failed: file too large'.
- Because of the corrected parenthesization, the skip condition for FLAG_ACTIVITY_NEW_DOCUMENT without FLAG_ACTIVITY_RETAIN_IN_RECENTS now takes effect. Activities that match it and are not the bottom-most activity are no longer written to task XML.
- PersistableBundle (via BaseBundle) gains a @hide getSize(). Bundle.getSize() semantics are unchanged.
Per major
- Android 14: Same fix: platform/frameworks/base 7926b8a53f28 in android-security-14.0.0_r31. The logic is identical and only the context differs. restoreTasksForUserLocked is structured differently, so the restore-path size check sits before the taskId parsing. 8/8 patched lines present.
- Android 15: Same fix: platform/frameworks/base ae2545402717 in android-security-15.0.0_r19 (the analysed commit). 8/8 patched lines present.
- Android 16: Same fix: platform/frameworks/base b0fa02818499 in android-security-16.0.0_r10. The logic is identical and only the context differs (WmProtoLogGroups imports, BaseBundle implements Parcel.ClassLoaderProvider). 8/8 patched lines present.
- Android 17: Same fix: platform/frameworks/base 49c44444a44a in android-security-17.0.0_r3. The logic is identical to 16. 8/8 patched lines present.
Unknowns
- The material does not show ActivityRecord.saveToXml, getPersistentSavedState, or how the persistent bundle is populated. It is therefore not shown whether the bundle is usually still parcelled at write time, which is when getSize() counts it.
- Tests are not included (the commit says they will follow). The original crash report details (bug 464276781) are not in the material.
- It is not shown whether the two internal Cherrypick-From source commits differ from this squashed change.
- The material does not show when restoreTasksForUserLocked is invoked, or whether TaskWriteQueueItem holds mGlobalLock on Android 15.