Skip to content

Commit

Permalink
Fix potential underrun with annotation merging (#54917)
Browse files Browse the repository at this point in the history
Fixes #54860, see the commit message for more details.

The added test serves as a MWE of the original bug report.
  • Loading branch information
tecosaur committed Jul 22, 2024
1 parent a1e0f5d commit e621c74
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/strings/annotated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ function _insert_annotations!(io::AnnotatedIOBuffer, annotations::Vector{Tuple{U
for i in reverse(axes(annotations, 1))
annot = annotations[i]
first(first(annot)) == 1 || continue
i <= length(io.annotations) || continue
if last(annot) == last(last(io.annotations))
valid_run = true
for runlen in 1:i
Expand Down
6 changes: 6 additions & 0 deletions test/strings/annotated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ end
@test write(aio2, Base.AnnotatedChar('c', [:b => 2, :c => 3, :d => 4])) == 1
@test Base.annotations(aio2) == [(1:2, :a => 1), (1:3, :b => 2), (3:3, :c => 3), (3:3, :d => 4)]
end
let aio2 = Base.AnnotatedIOBuffer()
@test write(aio2, Base.AnnotatedChar('a', [:b => 1])) == 1
@test write(aio2, Base.AnnotatedChar('b', [:a => 1, :b => 1])) == 1
@test read(seekstart(aio2), Base.AnnotatedString) ==
Base.AnnotatedString("ab", [(1:1, :b => 1), (2:2, :a => 1), (2:2, :b => 1)])
end
# Working through an IOContext
aio = Base.AnnotatedIOBuffer()
wrapio = IOContext(aio)
Expand Down

0 comments on commit e621c74

Please sign in to comment.