Skip to content

Commit

Permalink
Normalise out PDF binary streams
Browse files Browse the repository at this point in the history
This will avoid any binary streams leaking out, including those
generated by LuaTeX (which is much more keen to make them).
  • Loading branch information
josephwright committed Aug 2, 2018
1 parent 01e9aa0 commit 407f257
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 56 deletions.
37 changes: 26 additions & 11 deletions l3build-check.lua
Expand Up @@ -491,24 +491,39 @@ local function normalise_pdf(pdffile,npdffile)
local file = assert(open(pdffile, "rb"))
local contents = gsub(file:read("*all") .. "\n", "\r\n", "\n")
close(file)
local newcontent = ""
local skip = false
local new_content = ""
local stream_content = ""
local stream = false
for line in gmatch(contents, "([^\n]*)\n") do
if skip then
if stream then
if match(line,"endstream") then
skip = false
line = ""
stream = false
local binary = false
for i = 0, 31 do
if match(stream_content,char(i)) then
binary = true
break
end
end
if binary then
new_content = new_content .. "[BINARY STREAM]\n"
else
new_content = new_content .. stream_content
end
else
stream_content = stream_content .. line
end
elseif match(line,"currentfile eexec") then
skip = true
elseif match(line,"^stream$") then
stream = true
stream_content = ""
end
if not match(line, "^ *$") and not skip then
newcontent = newcontent .. line .. os_newline
if not match(line, "^ *$") and not stream then
new_content = new_content .. line .. os_newline
end
end
end
local newfile = open(npdffile, "w")
output(newfile)
write(newcontent)
write(new_content)
close(newfile)
end
Expand Down
48 changes: 3 additions & 45 deletions testfiles/00-test-2.tpf
Expand Up @@ -4,11 +4,7 @@
<<
/Length 73
>>
stream
BT
/F15 9.9626 Tf 92.921 759.927 Td [(#$%&)]TJ 0 -23.91 Td [(#$%&)]TJ
ET
endstream
BT/F15 9.9626 Tf 92.921 759.927 Td [(#$%&)]TJ 0 -23.91 Td [(#$%&)]TJETendstream
endobj
2 0 obj
<<
Expand All @@ -35,46 +31,8 @@ endobj
/Length3 0
/Length 8480
>>
stream
%!PS-AdobeFont-1.0: CMTT10 003.002
%%Title: CMTT10
%Version: 003.002
%%CreationDate: Mon Jul 13 16:17:00 2009
%%Creator: David M. Jones
%Copyright: Copyright (c) 1997, 2009 American Mathematical Society
%Copyright: (<http://www.ams.org>), with Reserved Font Name CMTT10.
% This Font Software is licensed under the SIL Open Font License, Version 1.1.
% This license is in the accompanying file OFL.txt, and is also
% available with a FAQ at: http://scripts.sil.org/OFL.
%%EndComments
FontDirectory/CMTT10 known{/CMTT10 findfont dup/UniqueID known{dup
/UniqueID get 5000832 eq exch/FontType get 1 eq and}{pop false}ifelse
{save true}{false}ifelse}{false}ifelse
11 dict begin
/FontType 1 def
/FontMatrix [0.001 0 0 0.001 0 0 ]readonly def
/FontName /TZCMOM+CMTT10 def
/FontBBox {-4 -233 537 696 }readonly def
/PaintType 0 def
/FontInfo 9 dict dup begin
/version (003.002) readonly def
/Notice (Copyright \050c\051 1997, 2009 American Mathematical Society \050<http://www.ams.org>\051, with Reserved Font Name CMTT10.) readonly def
/FullName (CMTT10) readonly def
/FamilyName (Computer Modern) readonly def
/Weight (Medium) readonly def
/ItalicAngle 0 def
/isFixedPitch true def
/UnderlinePosition -100 def
/UnderlineThickness 50 def
end readonly def
/Encoding 256 array
0 1 255 {1 index exch /.notdef put} for
dup 38 /ampersand put
dup 36 /dollar put
dup 35 /numbersign put
dup 37 /percent put
readonly def
currentdict end
[BINARY STREAM]
endstream
endobj
8 0 obj
<<
Expand Down

0 comments on commit 407f257

Please sign in to comment.