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

Throw an IllegalArgumentException when a file name or comment in gzip parameters encodes to a byte array with a 0 byte #618

Merged
merged 3 commits into from
Nov 30, 2024

Conversation

ddeschenes-1
Copy link
Contributor

When gzip parameters' filename or comment are encoded into bytes, no verification was made to avoid the \0 that internally terminates those gzip fields.

Thus, the string argument could have a \0, and/or encode into bytes that have a \0 (like with UTF-16 charsets).
This would silently corrupt the gzip member, as a reader would prematurely stop reading the filename or comment and begin reading the next piece, either the comment but inevitably the deflate stream, which would fail.

I thought also about limiting the length on write but the gzip spec has no limit. Limiting length on read (to protect memory) would be imposing an arbitrary limit too, like some gzip tools do. Either way, it would have to be an option like the charset on write, and it would be unusual to ask for such option on the GzipDecompressorInputStream. Using jdk 17 ScopedValues is not possible yet and it would be a very forgettable option to set anyway. Without some discussion, there is no point in placing another api facing change on constructors.

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

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

Hello @ddeschenes-1

Thank you for your PR!

  • Please see my 6 comments.
  • Make you to run mvn by itself to run all build checks before you push.

@garydgregory garydgregory changed the title (doc) Added safety check to avoid corrupting byte '0' in filename or comment of gzip parameters. Throw an IllegalArgumentException when a file name or comment in gzip parameters encodes to a byte array with a 0 byte Nov 30, 2024
@garydgregory garydgregory merged commit 632434c into apache:master Nov 30, 2024
19 checks passed
asfgit pushed a commit that referenced this pull request Nov 30, 2024
parameters encodes to a byte array with a 0 byte #618

- Sort members
- Better local var names in tests
- Use JUnit feature instead of custom code
- Add missing assertions
public void testLegalCommentOrFileName(final String charset, final String text) {
final GzipParameters p = new GzipParameters();
if (charset != null) {
p.setFileNameCharset(Charset.forName(charset));
Copy link
Member

Choose a reason for hiding this comment

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

@ddeschenes-1
In the future, make the parameter a Charset instead of a String and you won't need the test to do the conversion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no automatic converter from String to Charset in junit5.
Adding the necessary lines for a @ConvertWith converter class would be far more code than those 2 lines.

Copy link
Member

@garydgregory garydgregory Nov 30, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great. thank you internet for misleading me again. what is it gonna be in 10 more years...

btw, when is 1.28.0 releasing?

Copy link
Member

Choose a reason for hiding this comment

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

I'd first like to finish shepherding the current other Apache Commons release candidates to completion. Could be another week or two before this components gets a release candidate.

@garydgregory
Copy link
Member

@ddeschenes-1

Merged 🚀 TY!

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