From e1fa336ac4910b9e5b2096a5bc0f3c1b489364f4 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 15 May 2026 10:25:40 -0400
Subject: [PATCH] android: Don't ever enumerate absolute paths from the assets
tree.
This could happen if opendir() failed for a reason other than the directory
missing (for example, `opendir("/")` fails with EACCES.
Reference Issue #15587.
---
src/filesystem/posix/SDL_sysfsops.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/filesystem/posix/SDL_sysfsops.c b/src/filesystem/posix/SDL_sysfsops.c
index 6183485b22daa..35ee29e246842 100644
--- a/src/filesystem/posix/SDL_sysfsops.c
+++ b/src/filesystem/posix/SDL_sysfsops.c
@@ -97,9 +97,11 @@ bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback
DIR *dir = opendir(pathwithsep);
if (!dir) {
#ifdef SDL_PLATFORM_ANDROID // Maybe it's an asset... that didn't use an "assets://" URL?
- const bool retval = Android_JNI_EnumerateAssetDirectory(pathwithsep + extralen, cb, userdata);
- SDL_free(pathwithsep);
- return retval;
+ if (*pathwithsep != '/') { // don't fall back to asset tree for absolute paths, in case opendir() failed for other reasons, like opendir("/") returning EACCES.
+ const bool retval = Android_JNI_EnumerateAssetDirectory(pathwithsep + extralen, cb, userdata);
+ SDL_free(pathwithsep);
+ return retval;
+ }
#endif
SDL_free(pathwithsep);
return SDL_SetError("Can't open directory: %s", strerror(errno));