n-t-roff / heirloom-doctools

The Heirloom Documentation Tools: troff, nroff, and related utilities
http://n-t-roff.github.io/heirloom/doctools.html
Other
127 stars 23 forks source link

Fix `.substring` out-of-bounds index which can cause segfault #93

Closed mircea3 closed 4 years ago

mircea3 commented 4 years ago

If .substring stop index is beyond the end of the string, the loop iterating to obtain the substring seems to process one extra character. Depending on various circumstances, this can have either:

The following test document, when repeated multiple times, on my computer produces all of these 3 outcomes.

.do xflag 3
.mediasize 100p 100p
.lc_ctype ro_RO.UTF-8
.fp 1 R texgyreschola-regular otf
.po 10p
.ll 40p
.ds S abcd
.substring S 1 100
\*S
.substring S 1 100
\*S
.br

Expected output: "bcd cd".

P.S. Is just a pull request OK, or should it be accompanied with an open issue?

n-t-roff commented 4 years ago

Just a pull request is ok when it is sure that it is a suitable fix.