ref: 57e2ed362dfe517efe02504426e9220892a159c3
parent: 5a590125a2830e7106fa78dacb0e1a9991f8a4cb
author: Ali Gholami Rudi <[email protected]>
date: Sun Jun 23 18:04:55 EDT 2013
font: do not read more than NKERNS kerning pairs
--- a/font.c
+++ b/font.c
@@ -39,11 +39,13 @@
struct glyph *glyph = NULL;
struct glyph *prev = NULL;
int wid, type;
- while (fn->n < NGLYPHS) {
- if (fscanf(fin, "%s", name) != 1)
- break;
+ while (fscanf(fin, "%s", name) == 1) {
if (!font_section(fn, fin, name))
break;
+ if (fn->n >= NGLYPHS) {
+ skipline(fin);
+ continue;
+ }
fscanf(fin, "%s", tok);
glyph = prev;
if (strcmp("\"", tok)) {
@@ -68,17 +70,17 @@
{
char c1[ILNLEN], c2[ILNLEN];
int val;
- while (fn->n < NGLYPHS) {
- if (fscanf(fin, "%s", c1) != 1)
- break;
+ while (fscanf(fin, "%s", c1) == 1) {
if (!font_section(fn, fin, c1))
break;
if (fscanf(fin, "%s %d", c2, &val) != 2)
break;
- strcpy(fn->kern_c1[fn->nkern], c1);
- strcpy(fn->kern_c2[fn->nkern], c2);
- fn->kern[fn->nkern] = val;
- fn->nkern++;
+ if (fn->nkern < NKERNS) {
+ strcpy(fn->kern_c1[fn->nkern], c1);
+ strcpy(fn->kern_c2[fn->nkern], c2);
+ fn->kern[fn->nkern] = val;
+ fn->nkern++;
+ }
}
}
@@ -140,7 +142,7 @@
continue;
}
if (!strcmp("fontname", tok)) {
- skipline(fin);
+ fscanf(fin, "%s", fn->fontname);
continue;
}
if (!strcmp("named", tok)) {
--- a/roff.h
+++ b/roff.h
@@ -78,8 +78,8 @@
extern int dev_ver;
struct glyph {
- char name[FNLEN]; /* name of the glyph */
- char id[FNLEN]; /* device-dependent glyph identifier */
+ char name[GNLEN]; /* name of the glyph */
+ char id[GNLEN]; /* device-dependent glyph identifier */
struct font *font; /* glyph font */
int wid; /* character width */
int type; /* character type; ascender/descender */
@@ -87,6 +87,7 @@
struct font {
char name[FNLEN];
+ char fontname[FNLEN];
struct glyph glyphs[NGLYPHS];
int nglyphs;
int spacewid;