Skip to content
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

Fix possible buffer overflow in addMultirowsImg #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bptato
Copy link
Contributor

@bptato bptato commented Aug 5, 2023

In 4e46481, a workaround was applied to prevent buffer overruns in addMultirowsForm. Unfortunately, the same issue affects addMultirowsImg; I have been able to consistently reproduce it by enabling inline images and visiting https://html.spec.whatwg.org.

I have not yet figured out why exactly this can happen, but the start/end indices are calculated in the same way at both locations (i.e. at addMultirowsForm too), so it is unsurprising that the issue persists. For now, I've just copy-pasted the same bounds checks; further investigation might be needed on whether the COLPOS/columnPos functions themselves are faulty or they were just used incorrectly.

@rkta
Copy link
Contributor

rkta commented Aug 8, 2023 via email

@bptato
Copy link
Contributor Author

bptato commented Aug 12, 2023

I've started to look into this a bit more. Some of my observations so far:

  • The bounds check should be < 0, > l->size (so permit +1 on both sides).
    addMultirowsForm needs < 1, >= l->size because it then writes at the
    beginning/end of the bounds.
  • For testing, I printed positions of the problematic images on a 105-col
    terminal window with ./configure --disable-m17n. Then I checked the line
    of the last image (26727). As it turns out, it's positioned incorrectly, and
    overlays the text of a completely unrelated paragraph (the image is a
    flowchart of the parser, and is drawn over the paragraph 4.8.4.4.15
    Guidance for conformance checkers).

From this my conclusion is that COLPOS/columnPos are not the real culprit,
but something is amiss in the image placement code that causes images to
be positioned on lines that may be shorter than required by the image
width.

@bptato bptato force-pushed the fix-buffer-overrun branch from 9246212 to 46e2e46 Compare August 12, 2023 10:40
A hack to avoid buffer overrun most likely caused by printing
mis-positioned images on lines shorter than their intended line.

May be related to 4e46481.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants