@@ -3892,66 +3892,97 @@ class PartialEvaluator {
3892
3892
let defaultWidth = 0 ;
3893
3893
const glyphsVMetrics = [ ] ;
3894
3894
let defaultVMetrics ;
3895
- let i , ii , j , jj , start , code , widths ;
3896
3895
if ( properties . composite ) {
3897
- defaultWidth = dict . has ( "DW" ) ? dict . get ( "DW" ) : 1000 ;
3896
+ const dw = dict . get ( "DW" ) ;
3897
+ defaultWidth = Number . isInteger ( dw ) ? dw : 1000 ;
3898
+
3899
+ const widths = dict . get ( "W" ) ;
3900
+ if ( Array . isArray ( widths ) ) {
3901
+ for ( let i = 0 , ii = widths . length ; i < ii ; i ++ ) {
3902
+ let start = xref . fetchIfRef ( widths [ i ++ ] ) ;
3903
+ if ( ! Number . isInteger ( start ) ) {
3904
+ break ; // Invalid /W data.
3905
+ }
3906
+ const code = xref . fetchIfRef ( widths [ i ] ) ;
3898
3907
3899
- widths = dict . get ( "W" ) ;
3900
- if ( widths ) {
3901
- for ( i = 0 , ii = widths . length ; i < ii ; i ++ ) {
3902
- start = xref . fetchIfRef ( widths [ i ++ ] ) ;
3903
- code = xref . fetchIfRef ( widths [ i ] ) ;
3904
3908
if ( Array . isArray ( code ) ) {
3905
- for ( j = 0 , jj = code . length ; j < jj ; j ++ ) {
3906
- glyphsWidths [ start ++ ] = xref . fetchIfRef ( code [ j ] ) ;
3909
+ for ( const c of code ) {
3910
+ const width = xref . fetchIfRef ( c ) ;
3911
+ if ( typeof width === "number" ) {
3912
+ glyphsWidths [ start ] = width ;
3913
+ }
3914
+ start ++ ;
3907
3915
}
3908
- } else {
3916
+ } else if ( Number . isInteger ( code ) ) {
3909
3917
const width = xref . fetchIfRef ( widths [ ++ i ] ) ;
3910
- for ( j = start ; j <= code ; j ++ ) {
3918
+ if ( typeof width !== "number" ) {
3919
+ continue ;
3920
+ }
3921
+ for ( let j = start ; j <= code ; j ++ ) {
3911
3922
glyphsWidths [ j ] = width ;
3912
3923
}
3924
+ } else {
3925
+ break ; // Invalid /W data.
3913
3926
}
3914
3927
}
3915
3928
}
3916
3929
3917
3930
if ( properties . vertical ) {
3918
- let vmetrics = dict . getArray ( "DW2" ) || [ 880 , - 1000 ] ;
3931
+ const dw2 = dict . getArray ( "DW2" ) ;
3932
+ let vmetrics = isNumberArray ( dw2 , 2 ) ? dw2 : [ 880 , - 1000 ] ;
3919
3933
defaultVMetrics = [ vmetrics [ 1 ] , defaultWidth * 0.5 , vmetrics [ 0 ] ] ;
3920
3934
vmetrics = dict . get ( "W2" ) ;
3921
- if ( vmetrics ) {
3922
- for ( i = 0 , ii = vmetrics . length ; i < ii ; i ++ ) {
3923
- start = xref . fetchIfRef ( vmetrics [ i ++ ] ) ;
3924
- code = xref . fetchIfRef ( vmetrics [ i ] ) ;
3935
+ if ( Array . isArray ( vmetrics ) ) {
3936
+ for ( let i = 0 , ii = vmetrics . length ; i < ii ; i ++ ) {
3937
+ let start = xref . fetchIfRef ( vmetrics [ i ++ ] ) ;
3938
+ if ( ! Number . isInteger ( start ) ) {
3939
+ break ; // Invalid /W2 data.
3940
+ }
3941
+ const code = xref . fetchIfRef ( vmetrics [ i ] ) ;
3942
+
3925
3943
if ( Array . isArray ( code ) ) {
3926
- for ( j = 0 , jj = code . length ; j < jj ; j ++ ) {
3927
- glyphsVMetrics [ start ++ ] = [
3944
+ for ( let j = 0 , jj = code . length ; j < jj ; j ++ ) {
3945
+ const vmetric = [
3928
3946
xref . fetchIfRef ( code [ j ++ ] ) ,
3929
3947
xref . fetchIfRef ( code [ j ++ ] ) ,
3930
3948
xref . fetchIfRef ( code [ j ] ) ,
3931
3949
] ;
3950
+ if ( isNumberArray ( vmetric , null ) ) {
3951
+ glyphsVMetrics [ start ] = vmetric ;
3952
+ }
3953
+ start ++ ;
3932
3954
}
3933
- } else {
3955
+ } else if ( Number . isInteger ( code ) ) {
3934
3956
const vmetric = [
3935
3957
xref . fetchIfRef ( vmetrics [ ++ i ] ) ,
3936
3958
xref . fetchIfRef ( vmetrics [ ++ i ] ) ,
3937
3959
xref . fetchIfRef ( vmetrics [ ++ i ] ) ,
3938
3960
] ;
3939
- for ( j = start ; j <= code ; j ++ ) {
3961
+ if ( ! isNumberArray ( vmetric , null ) ) {
3962
+ continue ;
3963
+ }
3964
+ for ( let j = start ; j <= code ; j ++ ) {
3940
3965
glyphsVMetrics [ j ] = vmetric ;
3941
3966
}
3967
+ } else {
3968
+ break ; // Invalid /W2 data.
3942
3969
}
3943
3970
}
3944
3971
}
3945
3972
}
3946
3973
} else {
3947
- const firstChar = properties . firstChar ;
3948
- widths = dict . get ( "Widths" ) ;
3949
- if ( widths ) {
3950
- j = firstChar ;
3951
- for ( i = 0 , ii = widths . length ; i < ii ; i ++ ) {
3952
- glyphsWidths [ j ++ ] = xref . fetchIfRef ( widths [ i ] ) ;
3974
+ const widths = dict . get ( "Widths" ) ;
3975
+ if ( Array . isArray ( widths ) ) {
3976
+ let j = properties . firstChar ;
3977
+ for ( const w of widths ) {
3978
+ const width = xref . fetchIfRef ( w ) ;
3979
+ if ( typeof width === "number" ) {
3980
+ glyphsWidths [ j ] = width ;
3981
+ }
3982
+ j ++ ;
3953
3983
}
3954
- defaultWidth = parseFloat ( descriptor . get ( "MissingWidth" ) ) || 0 ;
3984
+ const missingWidth = descriptor . get ( "MissingWidth" ) ;
3985
+ defaultWidth = typeof missingWidth === "number" ? missingWidth : 0 ;
3955
3986
} else {
3956
3987
// Trying get the BaseFont metrics (see comment above).
3957
3988
const baseFontName = dict . get ( "BaseFont" ) ;
0 commit comments