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

CODEC-134: Update commons-codec to reject decoding any impossible string encoding for Base32 and Base64. #19

Merged
merged 4 commits into from
May 20, 2019

Conversation

tmousaw-ptc
Copy link
Contributor

Fix CODEC-134.

@tmousaw-ptc tmousaw-ptc changed the title Update commons-codec to reject decoding any impossible string encoding for Base32 and Base64. CODEC-134: Update commons-codec to reject decoding any impossible string encoding for Base32 and Base64. May 3, 2019
@coveralls
Copy link

coveralls commented May 3, 2019

Coverage Status

Coverage increased (+0.002%) to 92.369% when pulling f6195d3 on tmousaw-ptc:CODEC-134 into 0bf5b8a on apache:master.

@garydgregory
Copy link
Member

I am not sure I like the indirection of a method call just to shift some bits. That seems over the top to me.

@tmousaw-ptc
Copy link
Contributor Author

tmousaw-ptc commented May 3, 2019

@garydgregory - I completely agree with you. I'll rework that. I also noticed I'm missing some method parameters (the result of copy/paste). I'll fix that too.

@aherbert
Copy link
Contributor

aherbert commented May 3, 2019

You are using context.lbitWorkArea >> through the code. I assume this is OK and the work area will never be signed but does the unsigned operator work as well?

context.lbitWorkArea >>>

This makes more sense to me when pushing around bits with no care for the sign bit.

@tmousaw-ptc
Copy link
Contributor Author

@aherbert - That may be a valid concern, but that code existed before this change and, therefore, I feel it should not be changed under CODEC-134.

@garydgregory
Copy link
Member

@tmousaw-ptc ,

Would you mind doing a rebase on master one last time?

Thank you,

Gary

@tmousaw-ptc
Copy link
Contributor Author

@garydgregory - Rebased and pushed.

@garydgregory
Copy link
Member

Something went wrong with your git work. The PR now contains 91 files changed. Please redo.

… the given encoding for Base32 and Base64.

CODEC-134: Fix tabs instead of spaces.
…ished via a method call.

CODEC-134: Fix spaces versus tabs (again).
@tmousaw-ptc
Copy link
Contributor Author

@garydgregory Sorry about that. Missed a step in my rebase. Should be all set now.

@garydgregory
Copy link
Member

Sorry about one more thing: You should update changes.xml with your contribution.

@tmousaw-ptc
Copy link
Contributor Author

@garydgregory - No need to apologize. This is why we review, right? Updated.

@garydgregory garydgregory merged commit 48b6157 into apache:master May 20, 2019
@tmousaw-ptc tmousaw-ptc deleted the CODEC-134 branch May 20, 2019 16:12
jgallimore pushed a commit to jgallimore/commons-codec that referenced this pull request Sep 17, 2019
…ing encoding for Base32 and Base64. (apache#19)

[CODEC-134] Squash and merge.

* CODEC-134: Update to reject decoding strings that are not possible in the given encoding for Base32 and Base64.

* CODEC-134: Fix tabs instead of spaces.

* CODEC-134: Update such that the right shift is not indirectly accomplished via a method call.

* CODEC-134: Fix spaces versus tabs (again).

* CODEC-134: Add test to cover missed exception case in BCodec.java.

* CODEC-134: Update changes.xml to describe change.
jgallimore pushed a commit to jgallimore/commons-codec that referenced this pull request Sep 17, 2019
…ing encoding for Base32 and Base64. (apache#19)

[CODEC-134] Squash and merge.

* CODEC-134: Update to reject decoding strings that are not possible in the given encoding for Base32 and Base64.

* CODEC-134: Fix tabs instead of spaces.

* CODEC-134: Update such that the right shift is not indirectly accomplished via a method call.

* CODEC-134: Fix spaces versus tabs (again).

* CODEC-134: Add test to cover missed exception case in BCodec.java.

* CODEC-134: Update changes.xml to describe change.
jgallimore pushed a commit to tomitribe/commons-codec that referenced this pull request Sep 17, 2019
…ing encoding for Base32 and Base64. (apache#19)

[CODEC-134] Squash and merge.

* CODEC-134: Update to reject decoding strings that are not possible in the given encoding for Base32 and Base64.

* CODEC-134: Fix tabs instead of spaces.

* CODEC-134: Update such that the right shift is not indirectly accomplished via a method call.

* CODEC-134: Fix spaces versus tabs (again).

* CODEC-134: Add test to cover missed exception case in BCodec.java.

* CODEC-134: Update changes.xml to describe change.
@@ -30,7 +30,7 @@
*/
public class Base64TestData {

public static final String CODEC_101_MULTIPLE_OF_3 = "123";
public static final String CODEC_101_MULTIPLE_OF_3 = "124";
Copy link

Choose a reason for hiding this comment

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

ERhm... what's going on here?

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 can't say that I remember changing this and I'm not sure why I would have. It clearly doesn't make any sense.

Copy link

Choose a reason for hiding this comment

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

I dug in and found the reason: https://issues.apache.org/jira/browse/CODEC-134?focusedCommentId=13222167&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13222167
It should really be renamed to "three digit valid base64 value" or someting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! Thank you for digging this up! I knew there was some reason behind it, but since I made this change about a year and a half ago, I didn't remember why. Should've changed the constant name while I was at it to make it more clear and possibly add a comment to explain why 124 fits the bill.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this has already been merged for 1.13. The functionality was incomplete and was fixed in CODEC-270 for release 1.14. We have just released 1.15 that makes this functionality opt-in rather than always on. For version 1.15 trailing bit checking is off by default thus matching the behaviour from 1.12 and earlier where invalid trailing bits are discarded. You can enable it for strict decoding where invalid bits raise an exception when decoding.

Copy link

Choose a reason for hiding this comment

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

Yes, I found the strangely named variable when going through the changes in 1.15 (because 1.14 broke our builds). It just struck me that 123 is indeed a multiple of 3, but 124 isn't. Later on, I found out that it probably was meant as "valid b64 of length 3". Which works for 124 but not 123. So it's a poorly named variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

This variable dates back to an old bug for CODEC-101. The variable should have a byte length that is a multiple of 3. The issue is that the string 123 is not a valid base 64 encoding, so it had to change for this PR. I suggest a name change to CODEC_101_INPUT_LENGTH_IS_MULTIPLE_OF_3.

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.

5 participants