From: Afshin Arani Date: Sun, 10 Mar 2024 10:40:17 +0000 (+0200) Subject: CSharp: fix LDKStr array decoding X-Git-Tag: v0.0.121.3~5^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=dbcef74f9feb03aa6d8d0ee07854740cac926f6b;p=ldk-java CSharp: fix LDKStr array decoding 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) --- diff --git a/c_sharp/src/org/ldk/structs/Bolt11Invoice.cs b/c_sharp/src/org/ldk/structs/Bolt11Invoice.cs index 81fbf402..753798b9 100644 --- a/c_sharp/src/org/ldk/structs/Bolt11Invoice.cs +++ b/c_sharp/src/org/ldk/structs/Bolt11Invoice.cs @@ -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; } diff --git a/c_sharp/src/org/ldk/structs/Result_CVec_StrZIOErrorZ.cs b/c_sharp/src/org/ldk/structs/Result_CVec_StrZIOErrorZ.cs index 05e96f7f..7da2be50 100644 --- a/c_sharp/src/org/ldk/structs/Result_CVec_StrZIOErrorZ.cs +++ b/c_sharp/src/org/ldk/structs/Result_CVec_StrZIOErrorZ.cs @@ -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; } diff --git a/csharp_strings.py b/csharp_strings.py index 1121f934..e1c2708e 100644 --- a/csharp_strings.py +++ b/csharp_strings.py @@ -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