Quantcast
Channel: ImapX 2
Viewing all articles
Browse latest Browse all 1952

Commented Unassigned: Infinite loop in BodyStructureParser [2134]

$
0
0
Infinite loop in the second while loop of ReadQuotedString (line 314) of BodyStructureParser.cs

Call stack from my user code:
```
ImapX.dll!ImapX.Parsing.BodyStructureParser.ReadQuotedString(bool trimSpaces) Line 314 C#
ImapX.dll!ImapX.Parsing.BodyStructureParser.ReadString(bool trimSpaces) Line 265 C#
ImapX.dll!ImapX.Parsing.BodyStructureParser.ReadLanguage() Line 255 C#
ImapX.dll!ImapX.Parsing.BodyStructureParser.ParsePart(int number, int level) Line 201 C#
ImapX.dll!ImapX.Parsing.BodyStructureParser.Parse(int level) Line 42 C#
ImapX.dll!ImapX.Parsing.BodyStructureParser.Parse(int level) Line 38 C#
ImapX.dll!ImapX.Message.TryProcessBodyStructure(string data) Line 451 C#
ImapX.dll!ImapX.Message.ProcessCommandResult(string data) Line 243 C#
ImapX.dll!ImapX.Message.NormalizeAndProcessFetchResult(System.Collections.Generic.IList<string> data) Line 586 C#
ImapX.dll!ImapX.Message.Download(ImapX.Enums.MessageFetchMode mode, bool reloadHeaders) Line 554 C#
ImapX.dll!ImapX.Folder.Fetch(System.Collections.Generic.IEnumerable<long> uIds, ImapX.Enums.MessageFetchMode mode) Line 443 C#
ImapX.dll!ImapX.Folder.Search(long[] uIds, ImapX.Enums.MessageFetchMode mode) Line 505 C#
ImapX.dll!ImapX.Collections.MessageCollection.Download(long[] uIds, ImapX.Enums.MessageFetchMode mode) Line 41 C#
CLIGmail.exe!CLIGmail.Ls.Eval(ImapX.Folder mb) Line 90 C#
CLIGmail.exe!CLIGmail.REPL.Start() Line 145 C#
CLIGmail.exe!CLIGmail.Program.Main(string[] args) Line 222 C#
[External Code]
```

At this point, _reader contained the following string:
```
) NIL NIL) BODY[HEADER.FIELDS (FROM TO DATE SUBJECT CC CONTENT-TYPE)
```
The asymmetry of this looks suspicious, and the issue is probably further up from this method. The while loop continues to spin because there is no proper end condition and _reader.Read returns 65535 (char max value). Eventually memory runs out after the string builder becomes gigs long.

I was able to patch this by forcing the while loop to end on char max:
```
while ( ((currentChar = (char)_reader.Read()) != '"' || prevChar == '\\') && currentChar!=Char.MaxValue)
```
Comments: ** Comment from web user: xavierbeynon **

I will send you the offending email (an amazon newsletter) tonight so you have a proper test case.


Viewing all articles
Browse latest Browse all 1952

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>