terl / lazysodium-java

A Java implementation of the Libsodium crypto library. For the lazy dev.
https://github.com/terl/lazysodium-java/wiki
Mozilla Public License 2.0
135 stars 47 forks source link

Change binLen to pointer in hex2bin and base642bin #84

Closed ionspin closed 3 years ago

ionspin commented 3 years ago

Libsodium hex2bin and base642bin expect a pointer to binLen and hexEnd/b64End parameters. Links to libsodium source:

The binLen values are needed to calcualte correct size after conversion.

the hexEnd and b64End values are used by libsodium to store pointers to the next byte after the last parsed byte. Since it was previously just a byte parameter, libsodium would treat it as a address and try to write to that adrress causing JVM to crash

...
siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000007700000000

Register to memory mapping:

RAX=0x0 is NULL
RBX=0x00007fec0817973e points into unknown readable memory: 00 00
...

Also added tests to cover base64 and hex use cases.

This fixes #83

gurpreet- commented 3 years ago

Wow, thank you so much for this! Thanks for the tests too!