flexmark-java icon indicating copy to clipboard operation
flexmark-java copied to clipboard

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

Open bvarner opened this issue 2 years ago • 2 comments

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 avatar Jun 24 '22 02:06 bvarner

Looks like this is addressed by #503

bvarner avatar Jun 24 '22 13:06 bvarner

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

ghost avatar Jun 18 '23 21:06 ghost