vsch / flexmark-java

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
BSD 2-Clause "Simplified" License
2.29k stars 271 forks source link

flexmark-ext-resizable-image crashes on inline parsing when a block ends with an exclamation mark! #513

Open bvarner opened 2 years ago

bvarner commented 2 years ago

A markdown block like:

This is soooo cool!

![the thing](the_thing.jpg =120x60)

Will fail with a StringIndexOutOfBoundsException.

The issue is with ResizableImageInlineParserExtension.java

    @Override
    public boolean parse(@NotNull LightInlineParser inlineParser) {
        int index = inlineParser.getIndex();
        char c = inlineParser.getInput().charAt(index + 1);
        if (c == '[') {
            BasedSequence[] matches = inlineParser.matchWithGroups(IMAGE_PATTERN);

Note the use of index + 1 without a prior bounds check. The offending exclamation mark happens to be at the end of a block, so the index + 1 character check for a following [ puts us past the end of the block, and out of range.

Expected behavior If the input is not long enough to check the next character, it's clearly not going to be a [. This shouldn't crash. :-)

bvarner commented 2 years ago

Looks like this is addressed by #503

ghost commented 1 year ago

@bvarner: Would you mind closing your ticket if it is fixed?