<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jul 26, 2018 at 7:39 AM, Petr Kobalíček <span dir="ltr"><<a href="mailto:kobalicek.petr@gmail.com" target="_blank">kobalicek.petr@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I initially thought that this was to prevent an infinite recursion of contextual lookups.<br><br>I'm working with OpenType myself (not harfbuzz) and this is something that I think is not clarified in the specification. Can a contextual substitution invoke another contextual substitution and recurse?</div></blockquote><div><br></div><div>Yes it can.<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"> Is <span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">HB_CLOSURE_MAX_STAGES here to enforce hard limit?</span><br></div></blockquote><div><br></div><div>No. But neighboring HB_MAX_NESTING_LEVEL does that. Currently set to 6.<br><br></div><div>The font Noto Nastaliq Urdu uses nested recursive lookups extensively.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">To write a bit more about it. I thought that contextual lookup has basically 3 parts:<div><br></div><div> - backtrack sequence</div><div> - input sequence</div><div> - lookahead sequence<br><br>I would imagine that "input" sequence would be pretty short, like one character most of the time, and the lookup applied if we have a match would only consist of "input sequence". So the question is, does it make sense to apply another contextual lookup to just the isolated "input sequence" in case we had a match?<br></div></div></blockquote><div><br></div><div>Yes.<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Do you guys here know any material that would further explain how such cases of GSUB should be correctly handled?<br></div></div></blockquote><div><br></div><div>How HarfBuzz does it is my best understanding of how it should be done (not necessarily how Microsoft does it, but compatible-enough).<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Best,<br>Petr.<div><div class="gmail-h5"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 26, 2018 at 9:06 AM, Richard Wordingham <span dir="ltr"><<a href="mailto:richard.wordingham@ntlworld.com" target="_blank">richard.wordingham@ntlworld.<wbr>com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 24 Jul 2018 16:31:50 +0000 (UTC)<br>
<a href="mailto:behdad@kemper.freedesktop.org" target="_blank">behdad@kemper.freedesktop.org</a> (Behdad Esfahbod) wrote:<br>
<br>
The following change bothers me:<br>
<br>
> src/hb-ot-layout-common-privat<wbr>e.hh | 7 +++++++<br>
> src/hb-ot-layout.cc | 5 ++++-<br>
> 2 files changed, 11 insertions(+), 1 deletion(-)<br>
> <br>
> New commits:<br>
> commit 85646fdadb2f102333485e07425361<wbr>795b4e0412<br>
> Author: Garret Rieger <<a href="mailto:grieger@google.com" target="_blank">grieger@google.com</a>><br>
> Date: Mon Jul 23 15:37:18 2018 -0700<br>
> <br>
> [subset] Limit the iterations of the closure algorithm.<br>
> Prevents O(n^2) run times.<br>
> <br>
> diff --git a/src/hb-ot-layout-common-priv<wbr>ate.hh<br>
> b/src/hb-ot-layout-common-priv<wbr>ate.hh index 21caf9e9..7ff0dbeb 100644<br>
> --- a/src/hb-ot-layout-common-priv<wbr>ate.hh<br>
> +++ b/src/hb-ot-layout-common-priv<wbr>ate.hh<br>
> @@ -41,6 +41,13 @@<br>
> #ifndef HB_MAX_CONTEXT_LENGTH<br>
> #define HB_MAX_CONTEXT_LENGTH 64<br>
> #endif<br>
> +#ifndef HB_CLOSURE_MAX_STAGES<br>
> +/*<br>
> + * The maximum number of times a lookup can be applied during<br>
> shaping.<br>
> + * Used to limit the number of iterations of the closure algorithm.<br>
> + */<br>
> +#define HB_CLOSURE_MAX_STAGES 8<br>
> +#endif<br>
<br>
I presume that this is intended to prevent a denial of service attack,<br>
at the cost of trashing a subset font.<br>
<br>
In non-malicious use, how is the victim supposed to detect that and<br>
then how he needs to change HarfBuzz or his font? Does he have to read<br>
all the text using the subset font simply to detect a problem? How<br>
does one test that a font does not hit this limit? Does one have to<br>
iterate over the power set of the supported characters for each<br>
script? That's O(2^n) - impossible to do! <br>
<br>
The description of HB_CLOSURE_MAX_STAGES is completely wrong. I was<br>
initially alarmed because I have lookups that are invoked in more than<br>
8 places in substitution subtables. A more accurate, but still not<br>
perfect, definition, would be 'the maximum number of times lookup can<br>
change a bit of text'.<br>
<br>
A limit of 8 does not strike me as obviously generous. Some contextual<br>
changes can ripple through a string, and I would not be totally<br>
surprised to find that 8+1 or more lookups act on some irreducible<br>
strings in my Da Lekh font. The consolations are that there are<br>
probably shorter paths to create the resultant glyphs from the input<br>
set, and one iteration will often process several lookups in the<br>
correct sequence.<br>
<br>
Richard.<br>
______________________________<wbr>_________________<br>
HarfBuzz mailing list<br>
<a href="mailto:HarfBuzz@lists.freedesktop.org" target="_blank">HarfBuzz@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/harfbuzz" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/harfbuzz</a><br>
</blockquote></div><br></div></div></div></div></div>
<br>______________________________<wbr>_________________<br>
HarfBuzz mailing list<br>
<a href="mailto:HarfBuzz@lists.freedesktop.org">HarfBuzz@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/harfbuzz" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/harfbuzz</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">behdad<br><a href="http://behdad.org/" target="_blank">http://behdad.org/</a></div>
</div></div>