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

Fix minor bugs #389

Merged
merged 4 commits into from
Jul 4, 2024
Merged

Fix minor bugs #389

merged 4 commits into from
Jul 4, 2024

Conversation

Lbqds
Copy link
Member

@Lbqds Lbqds commented Jul 4, 2024

No description provided.

@Lbqds Lbqds requested review from polarker and h0ngcha0 July 4, 2024 13:02
import { ArrayCodec, DecodedArray } from './array-codec'

export interface PublicKeyHash {
publicKeyHash: Uint8Array
}

class PublicKeyHashCodec implements Codec<PublicKeyHash> {
parser = Parser.start().buffer('publicKeyHash', { length: 32 })
parser = fixedSizeBytes('publicKeyHash', 32)
Copy link
Member Author

Choose a reason for hiding this comment

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

We are encountering an issue with the binary-parser library, which causes the lockupScriptCodec.decode(hexToBinUnsafe('01ca40da2a3f')) function to return a run out of memory error:

  1. Because the prefix is 1, it attempts to decode P2MPKH.
  2. The decoded array size is huge. And even if from and to are out of the index, Uint8Array.subarray(from, to) does not throw an exception but returns an empty Uint8Array. Moreover, binary-parser does not check the length during runtime, leading to the allocation of a very large array and resulting in the out of memory error.

I feel like binary-parser lacks flexibility. It does not provide a direct way to check the size of the data. Currently it can only be checked through the wrapper.

Copy link
Member

@polarker polarker left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@Lbqds Lbqds merged commit 1ec0750 into master Jul 4, 2024
6 of 7 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.

2 participants