erdomke / RtfPipe

Library for processing rich-text format (RTF) streams
MIT License
121 stars 44 forks source link

ControlTag's _factory Dicttionary is not threadsafe #86

Open jespersh opened 1 year ago

jespersh commented 1 year ago

In an attempt to scale out, I found that https://github.com/erdomke/RtfPipe/blob/9851ab97d693037073d567d74346184ae2f3d4b3/RtfPipe/Tokens/ControlTag.cs#L38 is being accessed in a manner that isn't thread-safe inside of https://github.com/erdomke/RtfPipe/blob/9851ab97d693037073d567d74346184ae2f3d4b3/RtfPipe/Tokens/ControlTag.cs#L40-L51

It can show up as various exceptions, but in this case it's an System.IndexOutOfRangeException

   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at RtfPipe.ControlTag.Negate(ControlWord`1 word)
   at RtfPipe.Model.HtmlVisitor.GetNewStyles(IEnumerable`1 styles, HtmlTag tag)
   at RtfPipe.Model.HtmlVisitor.Visit(Element element)
   at RtfPipe.Model.HtmlVisitor.Visit(Element element)
   at RtfPipe.Model.HtmlVisitor.Visit(RtfHtml document)
   at RtfPipe.Rtf.ToHtml(RtfSource source, XmlWriter writer, RtfHtmlSettings settings)
   at RtfPipe.Rtf.ToHtml(RtfSource source, RtfHtmlSettings settings)