Skip to content

Commit 6e050d8

Browse files
sdk/ts: guard flexAlgoNodeSegments loop against pre-RFC-18 mainnet accounts
1 parent eb3b075 commit 6e050d8

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

  • sdk/serviceability/typescript/serviceability

sdk/serviceability/typescript/serviceability/state.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ function deserializeInterface(r: DefensiveReader): DeviceInterface {
550550
const segCount = r.readU32();
551551
const flexAlgoNodeSegments: FlexAlgoNodeSegment[] = [];
552552
for (let i = 0; i < segCount; i++) {
553+
// Break early if there isn't enough data for a full segment. On pre-RFC-18
554+
// mainnet accounts, segCount reads garbage bytes from the next field, so
555+
// without this guard the loop runs hundreds of thousands of times.
556+
if (r.remaining < 34) break; // 32 (pubkey) + 2 (u16)
553557
flexAlgoNodeSegments.push({
554558
topology: readPubkey(r),
555559
nodeSegmentIdx: r.readU16(),

0 commit comments

Comments
 (0)