From: Matt Corallo Date: Tue, 30 Nov 2021 01:38:04 +0000 (+0000) Subject: Check array lengths before passing them to C X-Git-Tag: v0.0.103.1^2~12 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=490adeaa3273fe53040c11f415782977895d0be7;hp=490adeaa3273fe53040c11f415782977895d0be7;p=ldk-java Check array lengths before passing them to C 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. ---