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 decompression functions not returning errcodes #58278

Merged
merged 1 commit into from
Feb 18, 2022

Conversation

rsubtil
Copy link
Contributor

@rsubtil rsubtil commented Feb 18, 2022

Compression::decompress returns -1 on error scenarios. This was not being propagated to let the user know there was an error while reading compressed files.

Fixes #57049

@rsubtil rsubtil requested a review from a team as a code owner February 18, 2022 13:43
@@ -305,7 +308,8 @@ uint64_t FileAccessCompressed::get_buffer(uint8_t *p_dst, uint64_t p_length) con
if (read_block < read_block_count) {
//read another block of compressed data
f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
int err = Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
Copy link
Member

Choose a reason for hiding this comment

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

Should be ret for consistency with other checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed 👍

@akien-mga akien-mga added bug cherrypick:3.x Considered for cherry-picking into a future 3.x release topic:core labels Feb 18, 2022
@akien-mga akien-mga added this to the 4.0 milestone Feb 18, 2022
@@ -125,10 +125,11 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
char rmagic[5];
f->get_buffer((uint8_t *)rmagic, 4);
rmagic[4] = 0;
if (magic != rmagic || open_after_magic(f) != OK) {
Error err = ERR_FILE_UNRECOGNIZED;
Copy link
Member

Choose a reason for hiding this comment

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

Shadows previous err:

Suggested change
Error err = ERR_FILE_UNRECOGNIZED;
err = ERR_FILE_UNRECOGNIZED;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed 👍

Comment on lines 278 to 279
int ret = Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
ERR_FAIL_COND_V_MSG(ret == -1, 0, "Compressed file is corrupt.");
Copy link
Member

Choose a reason for hiding this comment

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

This shadows ret which is actually the decompression result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, I picked total as a more sensible name than err for this one.

@akien-mga akien-mga merged commit 0217d44 into godotengine:master Feb 18, 2022
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 3.5.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Feb 19, 2022
@akien-mga
Copy link
Member

Cherry-picked for 3.4.3.

@rsubtil rsubtil deleted the fix_decompress_retcode branch February 22, 2023 10:10
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.

Corrupted compressed file can be read without errors in GDscript
2 participants