fix(importer): skip GPIF tempo automations on missing master bars#2668
Open
kaizenman wants to merge 2 commits intoCoderLine:developfrom
Open
fix(importer): skip GPIF tempo automations on missing master bars#2668kaizenman wants to merge 2 commits intoCoderLine:developfrom
kaizenman wants to merge 2 commits intoCoderLine:developfrom
Conversation
GpifParser._buildModel iterated _masterTrackAutomations and dereferenced score.masterBars[barNumber] without checking that the index was within range. Real-world GP7/8 files (off-by-one indexing, scores edited to fewer bars) reference bar numbers past the masterBars list, producing: TypeError: Cannot read properties of undefined (reading 'tempoAutomations') Skip the automation if the master bar is absent. The fixture test-data/guitarpro8/orphan-tempo-automation.gp has 100 master bars and a tempo automation targeting bar 100 (off-by-one) that previously crashed the importer.
5 tasks
Member
|
Thanks for the fixes, can you open counterpart bug reports following the template so we have proper tracking of these items? Also: the issue and PR templates are not optional, please be sure to update your description accordingly. |
1 similar comment
Member
|
Thanks for the fixes, can you open counterpart bug reports following the template so we have proper tracking of these items? Also: the issue and PR templates are not optional, please be sure to update your description accordingly. |
This was referenced Apr 25, 2026
1 task
Danielku15
requested changes
Apr 26, 2026
| // build masterbar automations | ||
| for (const [barNumber, automations] of this._masterTrackAutomations) { | ||
| const masterBar: MasterBar = this.score.masterBars[barNumber]; | ||
| const masterBar: MasterBar | undefined = this.score.masterBars[barNumber]; |
Member
There was a problem hiding this comment.
This is not C# and Kotlin transpilation compatible. Add a custom out-of-bounds check instead of relying on undefined returns.
kaizenman
added a commit
to kaizenman/alphaTab
that referenced
this pull request
Apr 28, 2026
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 CoderLine#2668. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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 CoderLine#2668.
5036de7 to
2206561
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues
Fixes #2675
Proposed changes
GpifParser._buildModeliterates_masterTrackAutomationsand dereferencesscore.masterBars[barNumber]without checking that the index is in range:On real-world Guitar Pro 7/8 files where the score has been edited (e.g. bars removed) without removing the corresponding
<MasterTrack>automations, or in files with off-by-one bar indices, this throws:Reproducer
test-data/guitarpro8/orphan-tempo-automation.gp— a published Guitar Pro 8 file with 100 master bars and tempo automations targeting bars[0, 91-95, 97-100]. The automation at bar 100 is one past the score's last bar (off-by-one).Fix
Skip the automation if the master bar is absent — matches Guitar Pro desktop behavior (silently ignores orphan automations and renders the score normally):
Tests
Gp8ImporterTest > orphan-tempo-automation— loads the fixture and assertsmasterBars.length === 100,tracks.length === 3. Without the fix this test throws the TypeError above.All 27 GP8 importer tests pass.
Note
One of three independent fixes in the same area. The others address distinct root causes:
Checklist
Further details