Skip to content

Fix crash in FileAccessCompressed and improve error handling - #77306

Open
RedworkDE wants to merge 1 commit into
godotengine:masterfrom
RedworkDE:file-access-compressed-error-handling
Open

Fix crash in FileAccessCompressed and improve error handling#77306
RedworkDE wants to merge 1 commit into
godotengine:masterfrom
RedworkDE:file-access-compressed-error-handling

Conversation

@RedworkDE

@RedworkDE RedworkDE commented May 21, 2023

Copy link
Copy Markdown
Member

Fixes partially #62585 (on MSVC #74582 is also required or it will just crash in CowData::resize before any of this matters)

Only the change in WRITE_FIT is strictly required to fix the crash.
The error handling improvements are required so that ResourceSaver::save doesn't OK when output file will be corrupted, with them it correctly returns ERR_CANT_CREATE.
Without the FileAccessCompressed::store_buffer implementation, the file writing will instead get stuck spamming errors for each byte in the buffer.

@RedworkDE
RedworkDE requested a review from a team as a code owner May 21, 2023 13:27
@akien-mga akien-mga added this to the 4.1 milestone May 21, 2023
@RedworkDE
RedworkDE force-pushed the file-access-compressed-error-handling branch from 49b7ccc to 30fee2e Compare May 22, 2023 18:44
@Calinou

Calinou commented Jun 18, 2023

Copy link
Copy Markdown
Member

The behavior of this PR rebased against master a83eb16 is the same as in the linked issue on Linux: no crash, but I still see the error message:

ERROR: Condition "p_size < 0" is true. Returning: ERR_INVALID_PARAMETER
   at: resize (./core/templates/cowdata.h:262)

test.res weighs 544,482,622 bytes when I exit the MRP after the error message is printed.

@RedworkDE

Copy link
Copy Markdown
Member Author

Other than the resize crash on MSVC, the crash caused by this might be ASAN only iirc.

Also the main difference is that with the PR ResourceSaver::save returns ERR_CANT_CREATE instead of OK when it fails. The save failing can't be fixed without redesigning how the compressed files work or adding support for 2GB+ arrays (and even then this PR is still useful as saving can still fail in some cases where it then still shouldn't return OK)

@TokisanGames

TokisanGames commented Jan 19, 2024

Copy link
Copy Markdown
Contributor

With PR #86730 merged, Godot still crashes in #62585. Applying this PR on top, it replaces the crash with an error popup. However large resource files are still not saved. See #62585 (comment) for details.

akien-mga
akien-mga previously approved these changes May 7, 2024

@akien-mga akien-mga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The changes look good to me.

I'll unlink #62585 as it won't be fully fixed yet, but this seems to be a step in the right direction.

@akien-mga

Copy link
Copy Markdown
Member

Would be worth rebasing as this was last updated a year ago.

@akien-mga akien-mga modified the milestones: 4.3, 4.4 May 28, 2024
@akien-mga akien-mga added cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release and removed cherrypick:4.1 labels May 28, 2024
@Repiteo Repiteo added the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label Feb 24, 2025
@Repiteo Repiteo modified the milestones: 4.4, 4.5 Feb 24, 2025
@akien-mga akien-mga removed cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release labels Mar 13, 2025
@Repiteo Repiteo modified the milestones: 4.5, 4.6 Aug 4, 2025
@akien-mga

Copy link
Copy Markdown
Member

Needs rebase if this is still relevant.

@Repiteo Repiteo modified the milestones: 4.6, 4.x Jan 18, 2026
@Repiteo
Repiteo dismissed akien-mga’s stale review June 22, 2026 18:18

Review is now stale

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.

6 participants