khaledhosny / ots

Sanitizer for OpenType
BSD 3-Clause "New" or "Revised" License
266 stars 63 forks source link

minimised font getting rejected by OTS #150

Closed Pomax closed 7 years ago

Pomax commented 7 years ago

A few years ago I wrote http://processingjs.nihongoresources.com/the_smallest_font/, on making the smallest possible font that is still accepted by all browsers. Since then, OTS has apparently been updated to reject this font, despite the fact that most modifications were made in spec-legal ways. The only truly spec-breaking modification was cropping the POST table, which should have zero effect on a font when used in the browser, so it would be interesting to see why OTS now treats this font as bad.

The font itself can trivially be generated with a hex editor by pasting the following hex code into a new otf file:

00 01 00 00 00 0A 00 80 00 03 00 20 4F 53 2F 32
71 95 70 D4 00 00 01 28 00 00 00 56 63 6D 61 70 
00 0C 00 74 00 00 01 88 00 00 00 2C 67 6C 79 66
01 04 62 39 00 00 01 BC 00 00 00 24 68 65 61 64 
DE 06 54 5C 00 00 00 AC 00 00 00 36 68 68 65 61
00 04 00 00 00 00 00 E4 00 00 00 24 68 6D 74 78 
00 00 00 00 00 00 01 80 00 00 00 06 6C 6F 63 61
00 12 00 08 00 00 01 B4 00 00 00 06 6D 61 78 70 
00 04 00 02 00 00 01 08 00 00 00 20 6E 61 6D 65
00 DF 1C AB 00 00 01 E0 00 00 00 B0 70 6F 73 74 
00 03 00 00 00 00 02 90 00 00 00 20 00 01 00 00
00 01 00 00 02 48 13 63 5F 0F 3C F5 00 0B 00 20 
00 00 00 00 B4 91 A2 80 00 00 00 00 CA 57 74 C6
00 00 00 00 00 01 00 01 00 00 00 00 00 00 00 00 
00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00
00 00 FF FF 00 01 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 01 00 01 00 00 00 02 00 02
00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 01 02 00 02 00 00 01
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 6E 6F 6F 70 00 40 00 23 00 23 00 01 00 00
00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 01 00 03 00 01
00 00 00 0C 00 04 00 20 00 00 00 04 00 04 00 01 
00 00 00 41 FF FF 00 00 00 41 FF FF FF C0 00 01
00 00 00 00 00 00 00 08 00 12 00 00 00 01 00 00 
00 00 00 00 00 00 00 00 00 00 31 00 00 01 00 00
00 00 00 01 00 01 00 01 00 00 31 37 01 01 00 00 
00 00 00 0E 00 AE 00 01 00 00 00 00 00 00 00 00
00 00 00 01 00 00 00 00 00 01 00 00 00 00 00 01 
00 00 00 00 00 02 00 00 00 00 00 01 00 00 00 00
00 03 00 00 00 00 00 01 00 00 00 00 00 04 00 00 
00 00 00 01 00 00 00 00 00 05 00 00 00 00 00 01
00 00 00 00 00 06 00 00 00 00 00 03 00 01 04 09 
00 00 00 00 00 00 00 03 00 01 04 09 00 01 00 00
00 00 00 03 00 01 04 09 00 02 00 02 00 00 00 03 
00 01 04 09 00 03 00 00 00 00 00 03 00 01 04 09
00 04 00 00 00 00 00 03 00 01 04 09 00 05 00 00 
00 00 00 03 00 01 04 09 00 06 00 00 00 00 00 40
00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

(it is a really tiny font =)

khaledhosny commented 7 years ago

That article is too long to follow, and I don’t know what to do with the above hex code to get a binary file. Please attach the actual binary file.

Pomax commented 7 years ago

Don't read the entire article, it's mostly irrelevant to this bug. The initial comment had all the information needed already.

As for the hex code, you paste it in any hex editor and save it as otf file, or you can even just use echo to write the sequence to file, but I'll try to attach the actual file for your convenience.

Pomax commented 7 years ago

hopefully this worked. github is pretty stupid about which filetypes it accepts as attachment.

small.zip

TTX, FontForge, Font Creator, Fontlab, etc. all read in this file just fine, and older versions of Firefox and the current version of Chrome load this file as a webfont without any complaint as well, so something in OTS became more aggressive to the point of rejecting fonts that the industry standard in practice says is perfectly fine.

khaledhosny commented 7 years ago

Thanks. I have no problem with the attached file:

$ ./ots-sanitize small.otf 
WARNING: maxp: Bad maxZones: 0
File sanitized successfully!
Pomax commented 7 years ago

Hm, I wonder whether they did something weird in FF Nightly to break OTS, then. I'm trying this on 58 and the console is full of sanitization errors. I'll do some more investigation here, thanks.