Skip to content

Commit

Permalink
ppltotf.ch: safer kanji hex code parsing (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminophen committed Jan 30, 2018
1 parent 12077c0 commit bfbe64d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
25 changes: 19 additions & 6 deletions source/texk/web2c/ptexdir/ppltotf.ch
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ incr(current_option);
We need to include some routines for handling kanji characters.

@<Constants...@>=
max_kanji=7237; { maximam number of 2byte characters }
max_kanji=7237; { maximum number of 2byte characters }
max_kanji_code=@"7E7E; { maximum jis code }
yoko_id_number=11; { is identifier for YOKO-kumi font}
tate_id_number=9; { is identifier for TATE-kumi font}
Expand Down Expand Up @@ -684,11 +685,9 @@ if ch=')' then
begin decr(loc); jis_code:=0;
end
else if (ch='J')or(ch='j') then
begin repeat ch:=get_next_raw; until ch<>' ';
cx:=todig(xord[ch])*@"1000;
incr(loc); ch:=xord[buffer[loc]]; cx:=cx+todig(ch)*@"100;
incr(loc); ch:=xord[buffer[loc]]; cx:=cx+todig(ch)*@"10;
incr(loc); ch:=xord[buffer[loc]]; cx:=cx+todig(ch);
begin repeat ch:=get_next_raw;
until ch<>' '; {skip the blanks after the type code}
@<Scan a Kanji hexadecimal code@>;
jis_code:=toDVI(fromJIS(cx)); cur_char:=ch;
if not valid_jis_code(jis_code) then
err_print('jis code ', jis_code:1, ' is invalid');
Expand All @@ -703,5 +702,19 @@ else jis_code:=-1;
get_kanji:=jis_code;
end;
@ @<Scan a Kanji hex...@>=
begin cx:=todig(xord[ch]);
incr(loc); ch:=xord[buffer[loc]];
while ((ch>="0")and(ch<="9"))or((ch>="A")and(ch<="F")) do
begin cx:=cx*16+todig(ch);
incr(loc); ch:=xord[buffer[loc]];
end;
decr(loc); ch:=xord[buffer[loc]];
if cx>max_kanji_code then
begin skip_error('This value shouldn''t exceed jis code');
cx:=0; ch:=" ";
end;
end
@* Index.
@z
29 changes: 7 additions & 22 deletions source/texk/web2c/uptexdir/uppltotf.ch
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
@z

@x
max_kanji=7237; { maximam number of 2byte characters }
max_kanji=7237; { maximum number of 2byte characters }
max_kanji_code=@"7E7E; { maximum jis code }
@y
max_kanji=1114111; { maximam number of 2byte characters }
max_kanji_code=@"10FFFF; { maximum ucs code }
@z

@x function get_next_raw
Expand Down Expand Up @@ -91,27 +93,10 @@ else if multistrlen(ustringcast(buffer), loc+2, loc)=2 then
incr(loc); cur_char:=" ";
@y
else if (ch='U')or(ch='u') then
begin repeat ch:=get_next_raw; until ch<>' ';
cx:=todig(xord[ch])*@"1000;
incr(loc); ch:=xord[buffer[loc]]; cx:=cx+todig(ch)*@"100;
incr(loc); ch:=xord[buffer[loc]]; cx:=cx+todig(ch)*@"10;
incr(loc); ch:=xord[buffer[loc]]; cx:=cx+todig(ch);
{ Uxxxx done, following code supports Uxxxxx and Uxxxxxx }
incr(loc); ch:=xord[buffer[loc]];
if (ch<>' ') then begin {5th digit found, proceed}
cx:=cx*@"10+todig(ch);
incr(loc); ch:=xord[buffer[loc]];
if (ch<>' ') then {6th digit found, proceed}
cx:=cx*@"10+todig(ch)
else begin {6th digit not found, recover}
decr(loc); ch:=xord[buffer[loc]];
end
end
else begin {5th digit not found, recover}
decr(loc); ch:=xord[buffer[loc]];
end;
jis_code:=toDVI(fromUCS(cx));
cur_char:=ch;
begin repeat ch:=get_next_raw;
until ch<>' '; {skip the blanks after the type code}
@<Scan a Kanji hexadecimal code@>;
jis_code:=toDVI(fromUCS(cx)); cur_char:=ch;
if not valid_jis_code(jis_code) then
err_print('jis code ', jis_code:1, ' is invalid');
end
Expand Down

0 comments on commit bfbe64d

Please sign in to comment.