Skip to content

Commit

Permalink
Fix string out of bounds for asset file opening. (#4673)
Browse files Browse the repository at this point in the history
When opening the assets folder as a file, an out-of-bounds string
pointer is passed to AAssetManager_open.

Also remove some logspam.

b/388599092
  • Loading branch information
jellefoks authored Jan 10, 2025
1 parent ca2b1f5 commit 26b6545
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions starboard/android/shared/file_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,20 @@ bool IsAndroidAssetPath(const char* path) {
(path[prefix_len] == '/' || path[prefix_len] == '\0');
}

bool IsAndroidAssetFile(const char* path) {
size_t prefix_len = strlen(g_app_assets_dir);
return path != NULL && strncmp(g_app_assets_dir, path, prefix_len) == 0 &&
path[prefix_len] == '/';
}

AAsset* OpenAndroidAsset(const char* path) {
if (!IsAndroidAssetPath(path) || g_asset_manager == NULL) {
SB_LOG(WARNING) << "Unable to open from Android Asset Manager: " << path;
if (!IsAndroidAssetFile(path) || g_asset_manager == NULL) {
errno = ENOENT;
return NULL;
}
const char* asset_path = path + strlen(g_app_assets_dir) + 1;
AAsset* result = AAssetManager_open(g_asset_manager, asset_path, AASSET_MODE_RANDOM);
if (!result) {
SB_LOG(WARNING) << "Unable to open from Android Asset Manager: " << path;
errno = ENOENT;
}
return result;
Expand Down

0 comments on commit 26b6545

Please sign in to comment.