Skip to content

Commit 5036de7

Browse files
kaizenmanclaude
andcommitted
fix(importer): use explicit bounds check for masterBars access
The previous masterBar lookup used `score.masterBars[barNumber]` with an `| undefined` type and an `if (!masterBar)` guard. That relies on JS array out-of-bounds returning undefined — not C# / Kotlin transpilation compatible, since the indexed access there throws IndexOutOfRangeException / IndexOutOfBoundsException before the undefined-check has a chance to run. Replace with an explicit `barNumber < 0 || barNumber >= length` guard before the access, matching the idiom already used 9 lines above for sustain-pedal markers (GpifParser.ts) and in Gp3To5Importer.ts:508. Addresses review feedback from @Danielku15 on PR #2668. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f5e2fff commit 5036de7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

packages/alphatab/src/importer/GpifParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,11 +2892,11 @@ export class GpifParser {
28922892

28932893
// build masterbar automations
28942894
for (const [barNumber, automations] of this._masterTrackAutomations) {
2895-
const masterBar: MasterBar | undefined = this.score.masterBars[barNumber];
2896-
if (!masterBar) {
2895+
if (barNumber < 0 || barNumber >= this.score.masterBars.length) {
28972896
// automation references a bar that is not in the score's masterBars list
28982897
continue;
28992898
}
2899+
const masterBar: MasterBar = this.score.masterBars[barNumber];
29002900
for (let i: number = 0, j: number = automations.length; i < j; i++) {
29012901
const automation: Automation = automations[i];
29022902
switch (automation.type) {

0 commit comments

Comments
 (0)