Skip to content

Decoded value is not same as encoded one #3

Open

Description

@raziel057

Hello,

I notice that your code is not working correctly in some cases. For example here:

var test = new Uint8Array([120,156,75,244,51,201,14,14,45,9,41,203,1,0,18,222,3,161]);
console.log('Original text:  ' + test.toString());
test = base45.encode(test)
console.log('Base45 encoded: ' + test);
test = base45.decode(test)
console.log('Base45 decoded: ' + test);

Produce the following log:

Original text:  120,156,75,244,51,201,14,14,45,9,41,203,1,0,18,222,3,161
Base45 encoded: 6BF4R9RO6/Y19V5YC5V50FH2TK0
Base45 decoded: 120,156,75,244,51,201,14,14,45,9,41,203,0,256,18,222,3,161

Is it normal that the decoded Uint8Array is not equals to the one provided for encode ?

Please note that the decoded Uint8Array generates an error when using zlib.inflate() function from https://github.com/nodeca/pako, but not the original one:

zlib.inflate(new Uint8Array([120,156,75,244,51,201,14,14,45,9,41,203,0,256,18,222,3,161]))
node_modules\pako\lib\inflate.js:384
  if (inflator.err) throw inflator.msg || msg[inflator.err];
                    ^
incorrect data check

Activity

  1. dirkx commented on Apr 23, 2021

    @dirkx
    Owner

    This is absolutely a bug !

  2. raziel057 commented on Apr 23, 2021

    @raziel057
    Author

    Thanks.

    Please note that I don't have this issue if I use the following implementation: https://github.com/ehn-digital-green-development/base45-js

  3. vitorpamplona commented on May 6, 2021

    @vitorpamplona

    @dirkx can you merge from https://github.com/ehn-digital-green-development/base45-js and release a new version?

    I can confirm the current version has several bugs (it fails to decode to the original payload in about 10% of the DGCs I create) and the version at EHN DGC seems to work flawlessly.

  4. vitorpamplona commented on May 6, 2021

    @vitorpamplona

    If you want to add another test case that fails in the production version but passes on the EHN DGC version

    const LONG_BYTE_ARRAY = [120, 156, 187, 212, 226, 187, 136, 81, 141, 197, 195, 205, 124, 121, 245, 17, 125, 119, 134, 5, 145, 140, 190, 139, 217, 164, 18, 166, 48, 125, 96, 145, 74, 9, 189, 112, 192, 146, 145, 121, 33, 227, 146, 228, 178, 212, 162, 84, 67, 61, 3, 61, 131, 228, 188, 196, 220, 37, 73, 105, 121, 165, 41, 234, 142, 69, 197, 135, 119, 228, 21, 43, 232, 42, 148, 37, 230, 41, 120, 36, 230, 164, 230, 37, 165, 231, 229, 185, 21, 37, 230, 29, 94, 158, 159, 89, 172, 235, 149, 159, 152, 151, 156, 150, 87, 82, 232, 226, 24, 20, 236, 239, 23, 108, 19, 230, 232, 103, 227, 225, 232, 227, 234, 151, 156, 158, 87, 146, 235, 22, 228, 232, 231, 236, 239, 25, 108, 227, 229, 239, 232, 151, 156, 146, 159, 148, 101, 100, 96, 96, 169, 107, 96, 164, 107, 100, 145, 88, 210, 184, 42, 169, 36, 61, 211, 194, 196, 192, 212, 216, 210, 192, 192, 44, 169, 164, 36, 203, 39, 192, 200, 208, 220, 208, 210, 66, 215, 56, 169, 164, 40, 211, 200, 204, 192, 196, 208, 212, 192, 192, 32, 41, 55, 49, 197, 208, 200, 216, 40, 169, 56, 185, 66, 210, 200, 192, 200, 80, 215, 192, 68, 215, 208, 56, 196, 208, 196, 202, 200, 192, 202, 192, 64, 219, 0, 68, 38, 165, 20, 161, 203, 154, 0, 197, 13, 161, 178, 37, 201, 21, 82, 238, 238, 46, 10, 110, 69, 149, 197, 57, 135, 23, 229, 233, 40, 248, 232, 122, 164, 230, 100, 38, 231, 231, 149, 167, 166, 39, 37, 231, 39, 249, 249, 36, 101, 22, 231, 251, 102, 230, 101, 22, 151, 20, 85, 42, 228, 167, 41, 132, 133, 7, 39, 37, 103, 86, 200, 148, 22, 229, 89, 149, 150, 37, 103, 2, 77, 179, 242, 243, 177, 2, 26, 163, 111, 97, 232, 232, 232, 97, 104, 230, 24, 21, 225, 144, 171, 88, 115, 99, 217, 222, 71, 119, 85, 180, 51, 194, 11, 76, 221, 85, 36, 18, 103, 159, 250, 250, 187, 181, 168, 233, 141, 247, 158, 162, 235, 223, 60, 219, 124, 246, 9, 188, 182, 169, 88, 245, 81, 111, 71, 153, 227, 26, 93, 71, 213, 164, 8, 241, 234, 85, 31, 167, 50, 52, 247, 47, 89, 204, 52, 57, 26, 0, 43, 202, 143, 209]; 
    
    describe("Field Failure", () => { 
        it("encode long byte array", () => strictEqual(b45.decode(b45.encode(LONG_BYTE_ARRAY)), LONG_BYTE_ARRAY));
    });
    
  5. pp-ps commented on Jun 21, 2021

    @pp-ps
    Contributor

    @raziel057 I happened to experience the same issue, it should be fixed in latest main after 1c53b26.

  6. vitorpamplona commented on Jun 21, 2021

    @vitorpamplona

    I have had new decoding problems with 1c53b26, so I moved out to this library which seems to have everything fixed. https://www.npmjs.com/package/base45.

  7. pp-ps commented on Jun 21, 2021

    @pp-ps
    Contributor

    @vitorpamplona I have not caught any error yet, do you have a test case?

  8. vitorpamplona commented on Jun 21, 2021

    @vitorpamplona

    Sorry, not really. I was basically doing

    try 
      oldVersion.decode()
    catch 
      newVersion.decode()  
    

    and when both of them were crashing I just gave up on the lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions