Check array lengths before passing them to C
authorMatt Corallo <git@bluematt.me>
Tue, 30 Nov 2021 01:38:04 +0000 (01:38 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 1 Dec 2021 14:14:13 +0000 (14:14 +0000)
When users pass a static-length array to C we currently CHECK its
length, asserting only if we are built in debug mode. In
production, we happily call JNI's `GetByteArrayRegion` with the
expected length, ignoring any errors. `GetByteArrayRegion`,
however, "THROWS ArrayIndexOutOfBoundsException: if one of the
indexes in the region is not valid.". While its somewhat unclear
what "THROWS" means in the context of a C API, it seems safe to
assume accessing return values after a "THROWS" condition is
undefined. Thus, we should ensure we check array lengths before
calling into C.

We do this here with a simple wrapper function added to
`org.ldk.util.InternalUtils` which checks an array is the correct
length before returning it.


No differences found