Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix string out of bounds for asset file opening. #4673

Merged

Conversation

jellefoks
Copy link
Member

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

When opening the assets folder as a file, an out-of-bounds
string pointer is passed to AAssetManager_open.

b/388599092
@jellefoks jellefoks enabled auto-merge (squash) January 8, 2025 23:53
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;
Copy link
Contributor

@zhongqiliang zhongqiliang Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check asset_path has content here?
IsAndroidAssetFile() above only check path has the asset directory + '/', maybe we should check it has content after '/' there, and it does not end with '/'?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the memory pointed by the path pointer corrupted? What is causing that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR, the "+1" on line 124 points out of bounds when the asset directory is passed into OpenAndroidAsset.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re colin: I don't want to change the logic in this PR, only fix the out-of-bounds pointer resulting in a crash. If the asset directory + '/' is passed, the function behaves the same before and after this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AAssetManager_open can handle empty asset_path? Sounds good to me then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that even if it can't handle it, that is a separate bug that exists before and after this PR, and it out of scope for this PR.

@jellefoks jellefoks requested review from zhongqiliang and y4vor and removed request for y4vor January 9, 2025 18:43
@jellefoks
Copy link
Member Author

Gentle ping?

@jellefoks jellefoks merged commit 26b6545 into youtube:25.lts.1+ Jan 10, 2025
291 of 296 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants