Closed masatake closed 7 months ago
Though the bug was mysterious. The fix is so simple and obvious. I will merge this in soon.
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
6701fc4
) 85.37% compared to head (3af25f9
) 85.38%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Close #3935.
C++ may return RESCAN_FAILED when giving a broken input. Just "private" is an example of a broken input:
When a parser returns RESCAN_FAILED, the main part must reset the state of parsing to the initial state. The main part records the initial state for the case when the reset is needed.
The bug comes from the code not implemented as the expectation:
EXPECTATION:
The state includes the position of tags output stream AND the number of emitted tags.
The "initial state" should be recorded at the time before running the parser and after emitted the parser-specific ptags.
ORIGINAL CODE: The number of emitted tags is recorded before the main part emitting the parser-specific ptags.
internalSortTags() takes the number of emitted tags. With the original, the number can become incorrect when the a parser returns RESCAN_FAILED.
Acknowledgments: @terminatorul found the minimum input for reproducing the bug. @leleliu008 found --disable-external-sort as the critical condition for reproducing the bug.