freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft-devel] Optional fields and stream reading in WOFF2


From: Werner LEMBERG
Subject: Re: [ft-devel] Optional fields and stream reading in WOFF2
Date: Mon, 10 Jun 2019 11:17:19 +0200 (CEST)

> I have been going through the WOFF2 specifications, and there a lot
> of optional fields in various tables.
> 
> For example, the header size is fixed (48 bytes), but the table
> directory (https://www.w3.org/TR/WOFF2/#table_dir_format) has
> 2 optional fields, `tag' and `transformLength'.  In addition, the
> data type 255UInt16 can be one to three bytes and UIntBase128 can be
> *upto* 5 bytes long.
> 
> My question is, how can reading these variable-length streams be
> handled with `FT_FRAME_ENTER' and supporting macros?

You can't.

> `FT_FRAME_ENTER' requires a fixed frame size, which I believe is
> always the number of bytes the cursor traverses by the time
> `FT_FRAME_EXIT' is called (please correct me if I am wrong about
> this).

Correct.

> This would mean that if I take the frame size to be the sum of the
> upper bounds of the sizes of all possible fields, I will be
> overshooting in most cases.  Is there a correct solution to this
> that I'm missing?

You have to split the handling into fixed-size and variable-size
parts.  For the fixed-size stuff you can use `FT_FRAME_*'; for the
remaining part you should probably use `FT_NEXT_*', together with
manual checking whether there is sufficient input.  Example:

  if ( p + 8 <= limit )
    return FT_THROW( Invalid_Table );
  foo = FT_NEXT_ULONG( p );
  bar = FT_NEXT_ULONG( p );

Have a look at `TT_Load_Simple_Glyph' for some real-world code.


    Werner

reply via email to

[Prev in Thread] Current Thread [Next in Thread]