Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSharp: fix LDKStr array decoding #151

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

aarani
Copy link
Contributor

@aarani aarani commented Mar 10, 2024

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)

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)
@@ -581,7 +581,7 @@ def get_java_arr_elem(self, elem_ty, arr_name, idx):
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 + ")"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: mind just including it in the first if (or breaking the pointer array ones into a second if)? Its really a pointer array and should be grouped with the if for pointer arrays (endswith("Array") || c_ty == "uintptr_t").

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, seems this was a bad copy/paste job from TypeScript.

@TheBlueMatt
Copy link
Collaborator

Eh, I'll just merge this since I want to do a new round of releases.

@TheBlueMatt TheBlueMatt merged commit 6ab8c07 into lightningdevkit:main Mar 13, 2024
3 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants