Hack for 32biy/64bit array in native shared code, needs safeguards
This commit is contained in:
parent
065abe1dab
commit
2801fb9484
@ -60,15 +60,15 @@ actual object LibsodiumUtil {
|
|||||||
actual fun unpad(paddedData: UByteArray, blocksize: Int) : UByteArray {
|
actual fun unpad(paddedData: UByteArray, blocksize: Int) : UByteArray {
|
||||||
val paddedDataCopy = paddedData.copyOf()
|
val paddedDataCopy = paddedData.copyOf()
|
||||||
val paddedDataCopyPinned = paddedDataCopy.pin()
|
val paddedDataCopyPinned = paddedDataCopy.pin()
|
||||||
var newSize = ULongArray(1) { 0UL }
|
var newSizeULong = ULongArray(1) { 0UL }
|
||||||
val newSizePinned = newSize.pin()
|
val newSizePinned = newSizeULong.pin()
|
||||||
sodium_unpad(
|
sodium_unpad(
|
||||||
newSizePinned.addressOf(0),
|
newSizePinned.addressOf(0) as kotlinx.cinterop.CValuesRef<platform.posix.size_tVar>, // TODO Find a better solution for this!
|
||||||
paddedDataCopyPinned.toPtr(),
|
paddedDataCopyPinned.toPtr(),
|
||||||
paddedData.size.convert(),
|
paddedData.size.convert(),
|
||||||
blocksize.convert()
|
blocksize.convert()
|
||||||
)
|
)
|
||||||
val unpaddedSize = newSize[0]
|
val unpaddedSize = newSizeULong[0]
|
||||||
if (unpaddedSize > Int.MAX_VALUE.toULong()) {
|
if (unpaddedSize > Int.MAX_VALUE.toULong()) {
|
||||||
throw RuntimeException("Unsupported array size (larger than Integer max value) $unpaddedSize")
|
throw RuntimeException("Unsupported array size (larger than Integer max value) $unpaddedSize")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user