Bugfix - Handle invalid characters when decoding #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using this library in a project, I ran into an issue when I wrote a test that passed intentionally "bad data" to the
decode
method.Specifically, when passing the invalid data to the decode method of the
GmpEncoder
, which usesgmp_init()
, the GMP extension was throwing an unchecked warning about the data not being a valid number within the specified base (62).I've recreated this error in the provided tests, along with a fix:
... Unfortunately, there's not a great way to check for this error at a higher level, due to GMP's usage of warnings and a
false
return value. Interestingly enough, I've actually run into this problem before when building my own library years ago, so I've actually reported this as a PHP bug, but it was closed with a "Won't Fix" status: https://bugs.php.net/bug.php?id=68002In any case, I've created this fix to handle the issue for both the GMP encoder's case and for the base encoder, as otherwise not handling this case could lead to an invalid decode result or "data-loss".