Skip to content

Commit c0f9939

Browse files
authored
fix(unicode_filter): dedupe cmap subtable offsets to avoid double-rebuild segment corruption
1 parent 8cb7579 commit c0f9939

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tools/unicode_filter.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,21 @@ int main(int argc, char **argv){
338338
if(!cmap_record){ fprintf(stderr,"No cmap table.\n"); return 1; }
339339

340340
uint16_t numSub = r16(buf+cmap_offset+2);
341+
uint32_t seen_offsets[MAX_RANGES*4];
342+
int seen_count = 0;
341343
for(int i=0;i<numSub;i++){
342344
uint8_t *rec = buf+cmap_offset+4+i*8;
343345
uint32_t off = r32(rec+4);
346+
347+
int already = 0;
348+
for(int k=0;k<seen_count;k++){
349+
if(seen_offsets[k]==off){ already=1; break; }
350+
}
351+
if(already) continue;
352+
if(seen_count < (int)(sizeof(seen_offsets)/sizeof(seen_offsets[0]))){
353+
seen_offsets[seen_count++] = off;
354+
}
355+
344356
uint8_t *sub = buf+cmap_offset+off;
345357
uint16_t fmt = r16(sub);
346358
if(fmt==12) rebuild_format12_safe(sub, &list);

0 commit comments

Comments
 (0)