New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HtmlParser.Parse throws InvalidOperationException #735

Closed
Metalnem opened this Issue Dec 26, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@Metalnem
Copy link

Metalnem commented Dec 26, 2018

HtmlParser.Parse throws InvalidOperationException on some HTML inputs. Here's the full program to reproduce one such case:

using AngleSharp.Parser.Html;

namespace AngleSharp.Run
{
  public class Program
  {
    public static void Main(string[] args)
    {
      string html = @"<svg><!DOCTYPE html><<template>html><desc><template>><p>p</p></body></html>";
      new HtmlParser().Parse(html);
    }
  }
}

And here is the stack trace:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Collections.dll: 'Stack empty.'
   at System.Collections.Generic.Stack`1.ThrowForEmptyStack()
   at System.Collections.Generic.Stack`1.Peek()
   at AngleSharp.Parser.Html.HtmlParserExtensions.SelectMode(Element element, Boolean isLast, Stack`1 templateModes)
   at AngleSharp.Parser.Html.HtmlDomBuilder.Reset()
   at AngleSharp.Parser.Html.HtmlDomBuilder.InTemplate(HtmlToken token)
   at AngleSharp.Parser.Html.HtmlDomBuilder.InBody(HtmlToken token)
   at AngleSharp.Parser.Html.HtmlDomBuilder.Parse(HtmlParserOptions options)
   at AngleSharp.Run.Program.Main(String[] args) in 

Found via SharpFuzz.

@FlorianRappl

This comment has been minimized.

Copy link
Contributor

FlorianRappl commented Dec 26, 2018

Hi @Metalnem please report all found cases. It is sufficient to report the HTML source, e.g.,

<svg><!DOCTYPE html><<template>html><desc><template>><p>p</p></body></html>

Thanks for the report!

@FlorianRappl FlorianRappl added this to the v0.10 milestone Dec 26, 2018

@Metalnem

This comment has been minimized.

Copy link

Metalnem commented Dec 26, 2018

They are all very similar, and will result in the same exception. I've found five different ones so far:

<svg><!DOCTYPE html><<template>html><desc><template>><p>p</p></body></html>

<svg><!DOCTYPE html><html><template><desc><template>><p>p</p></body></html>

<svg><!DOCTYPE html><<<template>tml><desc><template>><p>p</p></body></html>

<svg><!DOCTYPE html><<frameset>h<template>tml><desc><template>><p>p</p></body></html>

<svg><!DOCTYPE html><template>>html><desc><template>><p>p</p></body></html><pre>

FlorianRappl added a commit that referenced this issue Dec 29, 2018

FlorianRappl added a commit that referenced this issue Dec 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment