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

fetch_disk_trailer: Don't truncate the size verif #170

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

keentux
Copy link
Contributor

@keentux keentux commented Aug 6, 2024

@gdraheim
Copy link
Owner

gdraheim commented Aug 6, 2024

I dont quite understand this patch with its ifdef-moves. Isnt ist just about removing the "-2" on the if-clause?

@keentux
Copy link
Contributor Author

keentux commented Aug 7, 2024

Indeed, it's all about removing the "-2" from the if-clause.
But, in same time, it seems that if the ifndef is true, as explained in the comment bloc the value of (end - trailer) could eventually be the full size of disk_trailer struct minus 2.

                    /* if the file-comment is not present, it happens
                       that the z_comment field often isn't either *

And to avoid having multiple time if condition in the case where %ifndef isn't true, I thought moving the if condition into each section of the ifndef would be a good option. I found this way to do more optimized that only add a second loop condition if (end - tail >= __sizeof(*trailer)) after the #else

@gdraheim
Copy link
Owner

gdraheim commented Aug 7, 2024

Ahhh, it is just now that I see the if-clauses have been doubled. Sorry for missing that part when reading the patch first.

However I dont like that the if-conditions are different just for being able to spot a ZIP64 trailer. The code had been setup in just the way that if ZIP64 support is off (for having a very old compiler), we can still see the section in the file and get over it.

Actually, when re-reading the code, I have the impuls to remove the ifdefs all along. Support for pre-C99 compilers should not be thing anymore - it was when I started to write the library which goes all the way back to the 90ies.

@keentux
Copy link
Contributor Author

keentux commented Aug 7, 2024

Thanks for these additional information, I understand the need of the ifdefs and yes I agree with you about the support for pre-C99 should not be thing anymore :)

Following that, I am going to change the PR in just removing the "-2" from the if conditions without touching the ifdef and avoid having a duplicated condition. The changes should be less complex in that way.

* We must check if the tail obtained have the size of the zzip_disk_trailer
  struct. end - tail should be at least >= of the size but not size - 2.
  Where truncated by 2 was good for pre-C99 compilers.
* Fix gdraheim#165

Signed-off-by: vlefebvre <valentin.lefebvre@suse.com>
@gdraheim gdraheim merged commit 7a65df0 into gdraheim:develop Aug 7, 2024
4 checks passed
gdraheim added a commit that referenced this pull request Aug 8, 2024
@gdraheim
Copy link
Owner

gdraheim commented Aug 8, 2024

Some tests failed and showed that the patch is only correct for the ZIP64 trailer but for the traditionalzip trailer it is best to allow the comment field to be actually missing.

@keentux
Copy link
Contributor Author

keentux commented Aug 9, 2024

Oh, Thanks for the verification.

@keentux
Copy link
Contributor Author

keentux commented Aug 12, 2024

memcpy(trailer, tail, sizeof(*trailer) - sizeof_z_comment);

Shouldn't be "__sizeof_z_comment" instead of "sizeof_z_comment" ?

@gdraheim
Copy link
Owner

I dont see how that makes a difference - it is a precompiler-define anyway

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.

2 participants