Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/cjs/transaction.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,19 @@ class Transaction {
marker === Transaction.ADVANCED_TRANSACTION_MARKER &&
flag === Transaction.ADVANCED_TRANSACTION_FLAG
) {
hasWitnesses = true;
const { bigintValue: vinLenPeek, bytes: vinLenBytes } =
bufferutils_js_1.varuint.decode(buffer, bufferReader.offset);
const minInputSize = 41;
const remainingAfterVinLen =
buffer.length - bufferReader.offset - vinLenBytes;
if (
vinLenPeek === BigInt(0) ||
Number(vinLenPeek) * minInputSize > remainingAfterVinLen
) {
bufferReader.offset -= 2;
} else {
hasWitnesses = true;
}
} else {
bufferReader.offset -= 2;
}
Expand Down
16 changes: 15 additions & 1 deletion src/esm/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,21 @@ export class Transaction {
marker === Transaction.ADVANCED_TRANSACTION_MARKER &&
flag === Transaction.ADVANCED_TRANSACTION_FLAG
) {
hasWitnesses = true;
const { bigintValue: vinLenPeek, bytes: vinLenBytes } = varuint.decode(
buffer,
bufferReader.offset,
);
const minInputSize = 41;
const remainingAfterVinLen =
buffer.length - bufferReader.offset - vinLenBytes;
if (
vinLenPeek === BigInt(0) ||
Number(vinLenPeek) * minInputSize > remainingAfterVinLen
) {
bufferReader.offset -= 2;
} else {
hasWitnesses = true;
}
} else {
bufferReader.offset -= 2;
}
Expand Down
20 changes: 15 additions & 5 deletions ts_src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,33 @@ export class Transaction {

static fromBuffer(buffer: Uint8Array, _NO_STRICT?: boolean): Transaction {
const bufferReader = new BufferReader(buffer);

const tx = new Transaction();
tx.version = bufferReader.readUInt32();

const marker = bufferReader.readUInt8();
const flag = bufferReader.readUInt8();

let hasWitnesses = false;
if (
marker === Transaction.ADVANCED_TRANSACTION_MARKER &&
flag === Transaction.ADVANCED_TRANSACTION_FLAG
) {
hasWitnesses = true;
const { bigintValue: vinLenPeek, bytes: vinLenBytes } = varuint.decode(
buffer,
bufferReader.offset,
);
const minInputSize = 41;
const remainingAfterVinLen =
buffer.length - bufferReader.offset - vinLenBytes;
if (
vinLenPeek === BigInt(0) ||
Number(vinLenPeek) * minInputSize > remainingAfterVinLen
) {
bufferReader.offset -= 2;
} else {
hasWitnesses = true;
}
} else {
bufferReader.offset -= 2;
}

const vinLen = bufferReader.readVarInt();
for (let i = 0; i < vinLen; ++i) {
tx.ins.push({
Expand Down