Fix null-pointer dereference in SystemUtils::getSurroundingBarlines#559
Open
primoszj wants to merge 1 commit into
Open
Fix null-pointer dereference in SystemUtils::getSurroundingBarlines#559primoszj wants to merge 1 commit into
primoszj wants to merge 1 commit into
Conversation
On branch fix-null-deref-surrounding-barlines Changes to be committed: modified: source/score/system.cpp
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.
Summary
SystemUtils::getSurroundingBarlines()guardsnext_barwithassert(next_bar)and then dereferences it unconditionally. In Release builds the assert is compiled out, so the null is dereferenced and the program crashes withSIGSEGVinsideBarline::getPosition()the first time the MIDI player asks for the surrounding barlines at a position that has no strictly-later barline.Reproduction
Releasemode.Crash (Release build):
Root cause
MidiFile::load()iterates with:moveToNextBar()has an early-return path: iffindPositionChange()handles a repeat / direction / alternate ending, the function returns before the "advance to next system" branch. The returnedlocationcan therefore sit exactly on a system's end barline. On the next iteration,System::getNextBarline()correctly returnsnullptr(no barline strictly past the end), butgetSurroundingBarlines()dereferences it anyway. In Debug builds theassertcatches it; in Release builds it's a hard crash.current_barhas the same shape of bug ifpositionprecedes all barlines (no exact match and no previous barline), though that path is harder to reach.Fix
Treat "no strictly-later barline" as a legitimate end-of-system state rather than an invariant violation. Fall back to the system's end barline so that
MidiFile::load()sees an empty[current, next)range, emits no events for that bar, andmoveToNextBar()advances to the next system on the following iteration. Guardcurrent_barsymmetrically.Every
Systemis constructed with a start and an end barline, sofront()andback()are always valid.Test plan
getSurroundingBarlines(system, end_bar_position)on a freshSystemand asserts the returned pair refers to the end barline rather than crashing.