Search code examples
debuggingfontsbinarybyteopentype

OTS parsing error: CFF2: misaligned table


I just fixed the problem of getting another error (I think/hope), but now I'm getting this error:

OTS parsing error: CFF2: misaligned table

I am reading through the docs, but my question is if this error is because the CFF2 table is malformed, or because something preceding it is malformed causing it to be positioned at the wrong offset essentially. I can't tell from just this error message.

I looked and it seems that the CFF2 table appears at 156 byte mark, which 156 % 4 == 0, so it aligns on the 4th byte marker, which is recommended (required perhaps) by the Microsoft docs. So if it's saying "misaligned table", yet its start seems to be correct, I begin to assume it means something else, like the table is either malformed (causing some piece of it to be misaligned somehow, not sure how that would work though), or this bug is the wrong error message or something.

If I remove the CFF2 table, it gives me this:

OTS parsing error: cmap: misaligned table

But both tables are unlikely to be malformed, so something else is going on I think.


Solution

  • This error originates in the ots tool. It is telling you that the offset (as stored in the tableDirectory) for the table is not a multiple of 4. That is to say: the problem is in the tableDirectory, not necessarily the CFF2 table data (it doesn't even get to the point of attempting to parse the CFF2 table...it might also be wrong).

    As with the other questions you've posted here recently: it appears that whatever routine is writing your font's tableDirectory is doing it wrong, adding extra bytes or incorrect values for offset or length or similar problems. You really need to solve that first if you want your font to be parsed correctly by other tools.