Skip to content

Conversation

@nikitalita
Copy link
Contributor

FileAccess::open currently returns valid FileAccess files if the packed file has an error while opening (e.g. if the encrypted file fails to be decrypted) because it is currently not checking get_error() before returning. With FileAccessPack in particular, this can lead to buffer overreads due to reading parts of the PCK that aren't valid data.

This changes FileAccessPack to return valid errors with get_error() if there were errors opening the file, and changes FileAccess::open to check get_error() before returning.

@nikitalita nikitalita requested a review from a team as a code owner November 2, 2025 21:05
Comment on lines +171 to 174
if (err != OK) {
ret.unref();
}
return ret;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (err != OK) {
ret.unref();
}
return ret;
if (err == OK) {
return ret;
}

It should behave the same as if nullptr is returned, and try to fall back to raw file outside pack.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe this is correct behavior. If PackedData::get_singleton()->try_open_path returns a FileAccess object, that means that the path is in PackedData and thus the canonical file location is in the pack. If trying to open that file in the pack returned an error, it means that there's something catastrophically wrong with our environment (wrong encryption key, the pck got deleted in the middle of running, etc.) and we should fail here.

Copy link
Member

Choose a reason for hiding this comment

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

It should at least be consistent, so maybe:

  • check if pack has file using PackedData::get_singleton()->has_path
    • if found, try loading and fail if try_open_path return nullptr or returned file has error set.
    • if not found, try using filesystem.

Copy link
Member

@bruvzg bruvzg Nov 3, 2025

Choose a reason for hiding this comment

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

Or get_error check can be moved to the try_open_path and it can return nullptr if error is set (to avoid double file map lookup).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants