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

Base32.Rfc4648.Encode(long) fails for multiples of 256 #58

Closed
pschwarzpp opened this issue Sep 12, 2024 · 2 comments
Closed

Base32.Rfc4648.Encode(long) fails for multiples of 256 #58

pschwarzpp opened this issue Sep 12, 2024 · 2 comments
Assignees

Comments

@pschwarzpp
Copy link

Throws IndexOutOfRangeException.

using SimpleBase;

namespace SimpleBaseTests;

public class UnitTest1
{
    [Fact]
    public void Encode_Base32_Long()
    {
        var someFailures = FailingBase32Rfc4648Encodes().Take(10).ToArray();
        Assert.Empty(someFailures);
    }

    private IEnumerable<(long, Exception)> FailingBase32Rfc4648Encodes()
    {
        for (var val = 0; val >= 0; ++val)
        {
            (long, Exception)? problem = null;

            try
            {
                Base32.Rfc4648.Encode(val);
            }
            catch (Exception ex)
            {
                problem = (val, ex);
            }

            if (problem is not null)
            {
                yield return problem.Value;
                problem = null;
            }
        }
    }
}

will produce output like

Xunit.Sdk.EmptyException
Assert.Empty() Failure: Collection was not empty
Collection: [Tuple (0, System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at SimpleBase.Base32.Encode(UInt64 number)
   at SimpleBase.Base32.Encode(Int64 number)
   at SimpleBaseTests.UnitTest1.FailingBase32Rfc4648Encodes()+MoveNext() in C:\Projects\PS.Playgrounds\SimpleBaseTests\UnitTest1.cs:line 22), Tuple (256, System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at SimpleBase.Base32.Encode(UInt64 number)
   at SimpleBase.Base32.Encode(Int64 number)
   at SimpleBaseTests.UnitTest1.FailingBase32Rfc4648Encodes()+MoveNext() in C:\Projects\PS.Playgrounds\SimpleBaseTests\UnitTest1.cs:line 22), Tuple (512, System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at SimpleBase.Base32.Encode(UInt64 number)
   at SimpleBase.Base32.Encode(Int64 number)
   at SimpleBaseTests.UnitTest1.FailingBase32Rfc4648Encodes()+MoveNext() in C:\Projects\PS.Playgrounds\SimpleBaseTests\UnitTest1.cs:line 22), Tuple (768, System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at SimpleBase.Base32.Encode(UInt64 number)
   at SimpleBase.Base32.Encode(Int64 number)
   at SimpleBaseTests.UnitTest1.FailingBase32Rfc4648Encodes()+MoveNext() in C:\Projects\PS.Playgrounds\SimpleBaseTests\UnitTest1.cs:line 22), Tuple (1024, System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at SimpleBase.Base32.Encode(UInt64 number)
   at SimpleBase.Base32.Encode(Int64 number)
   at SimpleBaseTests.UnitTest1.FailingBase32Rfc4648Encodes()+MoveNext() in C:\Projects\PS.Playgrounds\SimpleBaseTests\UnitTest1.cs:line 22), ···]
   at SimpleBaseTests.UnitTest1.Encode_Base32_Long() in C:\Projects\PS.Playgrounds\SimpleBaseTests\UnitTest1.cs:line 11
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
@ssg ssg self-assigned this Sep 12, 2024
@ssg ssg closed this as completed in 0453a88 Sep 12, 2024
@ssg
Copy link
Owner

ssg commented Sep 12, 2024

Thanks @pschwarzpp! Will release 4.0.1 shortly

@pschwarzpp
Copy link
Author

Thanks a lot for fixing this so quickly!

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

No branches or pull requests

2 participants