Skip to content

Parsing font with potentially faulty GDEF table #789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JonasGruenwald opened this issue Feb 10, 2025 · 2 comments
Closed

Parsing font with potentially faulty GDEF table #789

JonasGruenwald opened this issue Feb 10, 2025 · 2 comments

Comments

@JonasGruenwald
Copy link

JonasGruenwald commented Feb 10, 2025

Hello, big fan of the package here!

I've got an issue that's maybe more of a question, not a bug in the package itself:

I'm trying to parse a font file and opentype.js is throwing this error:

'Unsupported GDEF table version.');

Now if I add the parsed tableVersion to the logged error message there, it's showing a value of 0.
It seems that something in the font file is incorrect, as that appears to not be a valid version for the GDEF table according to the spec I could find.

Now my thing is, I'd still like to parse that font file even though it has this inconsistency. I've added a local patch to my project as a workaround:

--- a/dist/opentype.js
+++ b/dist/opentype.js
@@ -13820,8 +13820,10 @@
 	    start = start || 0;
 	    var p = new Parser(data, start);
 	    var tableVersion = p.parseVersion(1);
-	    check.argument(tableVersion === 1 || tableVersion === 1.2 || tableVersion === 1.3,
-	        'Unsupported GDEF table version.');
+	    if(!(tableVersion === 1 || tableVersion === 1.2 || tableVersion === 1.3)){
+        console.warn(`Unsupported GDEF table version: ${tableVersion}, not parsing table!`);
+        return undefined;
+      }
 	    var gdef = {
 	        version: tableVersion,
 	        classDef: p.parsePointer(Parser.classDef),

Also worth noting that any other software seems to be able to open the font file just fine, and FontForge for example does not report any issues when loading the font.

My questions are:

Would some form of fault tolerant parsing be in scope for opentype.js?
Would contributions along those lines be welcome?
Or does the project generally only aim to be able to parse files that 100% adhere to the spec?

@Connum
Copy link
Contributor

Connum commented Feb 24, 2025

I see you've closed the issue after receiving no response - I thought I had answered, but obviously I haven't! A more graceful approach to parsing has been implemented in this PR: #704 However, development and other contribution like reviewing has apparently come to a halt in the past few months.

@JonasGruenwald
Copy link
Author

@Connum Oh that's really cool to see, great work on this PR!
Yes I closed the issue because my personal need for this disappeared and I thought it better to not overwhelm the maintainers with irrelevant issues since there's probably a lot of other stuff to do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants