]> git.bitcoin.ninja Git - ldk-java/commitdiff
CSharp: fix LDKStr array decoding
authorAfshin Arani <afshin@arani.dev>
Sun, 10 Mar 2024 10:40:17 +0000 (12:40 +0200)
committerAfshin Arani <afshin@arani.dev>
Sun, 10 Mar 2024 10:49:27 +0000 (12:49 +0200)
Strings are encoded as array of string references, those references
are actually pointers to the string location and have 64bit in size,
but decoding logic was decoding those pointers as 32bit which caused
the following exception, this commit fixes that.

Exception:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at InternalUtils.getArrayLength(Int64)
   at InternalUtils.decodeUint8Array(Int64)
   at InternalUtils.decodeString(Int64)
   at org.ldk.structs.Result_CVec_StrZIOErrorZ+Result_CVec_StrZIOErrorZ_OK..ctor(System.Object, Int64)
   at org.ldk.structs.Result_CVec_StrZIOErrorZ.constr_from_ptr(Int64)
   at org.ldk.structs.KVStore.list(System.String, System.String)

c_sharp/src/org/ldk/structs/Bolt11Invoice.cs
c_sharp/src/org/ldk/structs/Result_CVec_StrZIOErrorZ.cs
csharp_strings.py

index 81fbf4029160a29a15592939f2a25e6781909ebe..753798b9dbfe4a75e1e9126f370acde779ebd8c5 100644 (file)
@@ -307,7 +307,7 @@ public class Bolt11Invoice : CommonBase {
                int ret_conv_8_len = InternalUtils.getArrayLength(ret);
                string[] ret_conv_8_arr = new string[ret_conv_8_len];
                for (int i = 0; i < ret_conv_8_len; i++) {
-                       long ret_conv_8 = InternalUtils.getU32ArrayElem(ret, i);
+                       long ret_conv_8 = InternalUtils.getU64ArrayElem(ret, i);
                        string ret_conv_8_conv = InternalUtils.decodeString(ret_conv_8);
                        ret_conv_8_arr[i] = ret_conv_8_conv;
                }
index 05e96f7f7e688c2ffbbc3d297453366f88cb039d..7da2be506c871897f99cfa4b954b17984ed37d45 100644 (file)
@@ -25,7 +25,7 @@ public class Result_CVec_StrZIOErrorZ : CommonBase {
                        int res_conv_8_len = InternalUtils.getArrayLength(res);
                        string[] res_conv_8_arr = new string[res_conv_8_len];
                        for (int i = 0; i < res_conv_8_len; i++) {
-                               long res_conv_8 = InternalUtils.getU32ArrayElem(res, i);
+                               long res_conv_8 = InternalUtils.getU64ArrayElem(res, i);
                                string res_conv_8_conv = InternalUtils.decodeString(res_conv_8);
                                res_conv_8_arr[i] = res_conv_8_conv;
                        }
index 1121f93413fc2975e1a398b9235d6f41d4dbb7f3..e1c2708e82e32ebcce0ea8dabe509c012675397a 100644 (file)
@@ -581,7 +581,7 @@ int CS_LDK_register_{fn_suffix}_invoker(invoker_{fn_suffix} invoker) {{
         elif elem_ty.rust_obj == "LDKU5":
             return "InternalUtils.getU8ArrayElem(" + arr_name + ", " + idx + ")"
         elif elem_ty.rust_obj == "LDKStr":
-            return "InternalUtils.getU32ArrayElem(" + arr_name + ", " + idx + ")"
+            return "InternalUtils.getU64ArrayElem(" + arr_name + ", " + idx + ")"
         else:
             assert False