After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 118592 - Length overruns when skipping glyphs
Length overruns when skipping glyphs
Status: RESOLVED FIXED
Product: pango
Classification: Platform
Component: general
1.2.x
Other Linux
: High normal
: 1.4.1
Assigned To: pango-maint
pango-maint
Depends on:
Blocks:
 
 
Reported: 2003-07-29 16:11 UTC by Owen Taylor
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to ftxgsub.c (4.97 KB, patch)
2003-08-11 08:01 UTC, Kailash C. Chowksey
none Details | Review
Patch as applied (38.57 KB, patch)
2004-07-19 20:39 UTC, Owen Taylor
none Details | Review

Description Owen Taylor 2003-07-29 16:11:55 UTC
[ Part of bug 118472, reported by Kailash C. Chowksey ]

When checking for glyphs that should be skipped because
of LookupFlags, the code is typically like:

    for ( numlig = ls->LigatureSet[index].LigatureCount;
          numlig;
          numlig--, lig++ )
    {

      if ( in->pos + lig->ComponentCount > in->length )
        continue;                         /* Not enough glyphs in input */
 
[....]

      for ( i = 1, j = 1; i < lig->ComponentCount; i++, j++ )
      {
        while ( CHECK_Property( gdef, s_in[j], flags, &property ) )
        {
          if ( error && error != TTO_Err_Not_Covered )
            return error;
                                                                          
     
          if ( in->pos + j < in->length )
            j++;
          else
            break;
        }
[...]
        if ( s_in[j] != c[i - 1] )
          break;
      }

      if ( i == lig->ComponentCount )
      {
         [ Apply this ligature ]
      }
    }

The initial length check is an initial approximation and probably
useful as a speedup, but not sufficient because we are skipping glyphs;
also there is an off-by-one 

There are various ways that this could be fixed up. I think the
cleanest would be:

     for ( numlig = ls->LigatureSet[index].LigatureCount;
          numlig;
          numlig--, lig++ )
    {
      if ( in->pos + lig->ComponentCount > in->length )
        continue;                         /* Not enough glyphs in input */
       
     [...]
     for ( i = 1, j = 1; i < lig->ComponentCount; i++, j++ )
      {
       if ( in->pos + j == in->length )
          goto next_ligature;

        while ( CHECK_Property( gdef, s_in[j], flags, &property ) )
        {
          if ( error && error != TTO_Err_Not_Covered )
            return error;
                                                                          
     
          j++; 
          if ( in->pos + j == in->length )
            goto next_ligature;
        }
[...]
        if ( s_in[j] != c[i - 1] )
          goto next_ligature;
      }

    [ Apply this ligature ]

   next_ligature: ;
   }

There are, by a rough count, about a dozen places that need
fixing in ftxgsub.c and a dozen more in ftxgpos.c.
Comment 1 Kailash C. Chowksey 2003-08-11 08:01:17 UTC
Created attachment 19100 [details] [review]
patch to ftxgsub.c
Comment 2 Kailash C. Chowksey 2003-08-11 08:04:33 UTC
I have thoroughly tested the above patch for ftxgsub.c using
all kinds of GSUB lookups affected by this patch. Please see
http://www.arbornet.org/~klchxbec/example.ttx for testcases
that were used to test this patch.

I cannot test fixes to ftxgpos.c due to some bugs in TTX.
Please consider checking-in only the ftxgsub.c fixes for now
since they fix a majority of rendering problems for indic
languages.
Comment 3 Owen Taylor 2003-08-25 14:49:19 UTC
I'd really rather have entirely untested fixes for GPOS
than leave ftxgsub.c and ftxgpos.c inconsistent.

Pushing off to 1.2.5 since I don't have time to review
in detail at the moment, and it's a rather big patch
to apply right before a release.
Comment 4 Owen Taylor 2004-07-19 20:38:08 UTC
The interrnals of ftxgsub.c and ftxgpos.c changed a fair  bit in Pango-1.4
so I had to start over pretty much from scratch. I also rewrote some
of the index handling to reduce the total amount of code and complexity.

Mon Jul 19 16:29:45 2004  Owen Taylor  <otaylor@redhat.com>
 
        * pango/opentype/ftxgsub.c pango/opentype/ftxgpos.c:
        Fix pervasive buffer overruns when skipping glyphs
        when matching contexts. (#118592, Kailash C. Chowksey)
Comment 5 Owen Taylor 2004-07-19 20:39:05 UTC
Created attachment 29670 [details] [review]
Patch as applied

Here's the patch I applied. Testing (even just of the GSUB portions)
would be appreciated.