summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2013-12-07 14:22:56 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2013-12-07 14:22:56 +0000
commitd85a200b2ae326d547e192c61d1647bf9b5ebffb (patch)
tree18daadab45d57c3a70fd646c6ceb0ad99b6ed1e9 /Build
parent371f7657572dbd472b707c32448d5b5f92663078 (diff)
luatex: Fix a serious bug related to large numbers in pdfimages (from Akira)
git-svn-id: svn://tug.org/texlive/trunk@32353 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
-rw-r--r--Build/source/texk/web2c/luatexdir/ChangeLog12
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writet3.w4
-rw-r--r--Build/source/texk/web2c/luatexdir/image/pdftoepdf.w2
-rw-r--r--Build/source/texk/web2c/luatexdir/image/writejp2.w2
-rw-r--r--Build/source/texk/web2c/luatexdir/pdf/pdfgen.w12
-rw-r--r--Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w14
-rw-r--r--Build/source/texk/web2c/luatexdir/pdf/pdfimage.w8
-rw-r--r--Build/source/texk/web2c/luatexdir/pdf/pdfpage.w20
-rw-r--r--Build/source/texk/web2c/luatexdir/pdf/pdfrule.w8
-rw-r--r--Build/source/texk/web2c/luatexdir/pdf/pdftypes.h5
10 files changed, 50 insertions, 37 deletions
diff --git a/Build/source/texk/web2c/luatexdir/ChangeLog b/Build/source/texk/web2c/luatexdir/ChangeLog
index 9c8650272dd..f133fd52e00 100644
--- a/Build/source/texk/web2c/luatexdir/ChangeLog
+++ b/Build/source/texk/web2c/luatexdir/ChangeLog
@@ -1,3 +1,15 @@
+2013-12-07 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ Fix a serious bug related to large numbers in pdfimages.
+ Mail from Akira Kakuto <kakuto@fuk.kindai.ac.jp>, 6 Dec 2013.
+ * pdf/pdftypes.h: Change pdffloat.m from long to int64_t.
+ Define i32round(a) and i64round(a) instead of lround(a).
+ * font/writet3.w: Cast arg2 of setpdffloat to int64_t.
+ * image/writejp2.w: Use uint64_t instead of unsigned long long.
+ * image/pdftoepdf.w, pdf/pdfgen.w, pdf/pdfglyph.w,
+ pdf/pdfimage.w, pdf/pdfpage.w, pdf/pdfrule.w: Replace lround(a)
+ by i32round(a) or i64round(a).
+
2013-09-20 Karl Berry <karl@tug.org>
* lua/luainit.w (lua_initialize) [NATIVE_TEXLIVE_BUILD]: omit date.
diff --git a/Build/source/texk/web2c/luatexdir/font/writet3.w b/Build/source/texk/web2c/luatexdir/font/writet3.w
index 990fcf4b2b1..4067205b28f 100644
--- a/Build/source/texk/web2c/luatexdir/font/writet3.w
+++ b/Build/source/texk/web2c/luatexdir/font/writet3.w
@@ -194,7 +194,7 @@ static boolean writepk(PDF pdf, internal_font_number f)
pdf_dict_add_streaminfo(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
- setpdffloat(pf, (int) t3_char_widths[cd.charcode], 2);
+ setpdffloat(pf, (int64_t) t3_char_widths[cd.charcode], 2);
print_pdffloat(pdf, pf);
pdf_printf(pdf, " 0 %i %i %i %i d1\n",
(int) llx, (int) lly, (int) urx, (int) ury);
@@ -324,7 +324,7 @@ void writet3(PDF pdf, internal_font_number f)
pdf_begin_array(pdf);
if (is_pk_font)
for (i = first_char; i <= last_char; i++) {
- setpdffloat(pf, (int) t3_char_widths[i], 2);
+ setpdffloat(pf, (int64_t) t3_char_widths[i], 2);
print_pdffloat(pdf, pf);
pdf_out(pdf, ' ');
} else
diff --git a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w
index 9c2e4b9f868..4b4b73073e2 100644
--- a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w
+++ b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w
@@ -279,7 +279,7 @@ static pdffloat conv_double_to_pdffloat(double n)
{
pdffloat a;
a.e = 6;
- a.m = lround(n * ten_pow[a.e]);
+ a.m = i64round(n * ten_pow[a.e]);
return a;
}
diff --git a/Build/source/texk/web2c/luatexdir/image/writejp2.w b/Build/source/texk/web2c/luatexdir/image/writejp2.w
index 47424d1c416..6228c1c52d4 100644
--- a/Build/source/texk/web2c/luatexdir/image/writejp2.w
+++ b/Build/source/texk/web2c/luatexdir/image/writejp2.w
@@ -54,7 +54,7 @@ typedef struct {
unsigned int tbox;
} hdr_struct;
-static unsigned long long read8bytes(FILE * f)
+static uint64_t read8bytes(FILE * f)
{
uint64_t l = read4bytes(f);
l = (l << 32) + read4bytes(f);
diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfgen.w b/Build/source/texk/web2c/luatexdir/pdf/pdfgen.w
index 490d2f96d12..21864e158b0 100644
--- a/Build/source/texk/web2c/luatexdir/pdf/pdfgen.w
+++ b/Build/source/texk/web2c/luatexdir/pdf/pdfgen.w
@@ -581,8 +581,8 @@ void pdf_print_int(PDF pdf, longinteger n)
void print_pdffloat(PDF pdf, pdffloat f)
{
char a[24];
- int e = f.e, i, j;
- long l, m = f.m;
+ int e = f.e, i, j, l;
+ int64_t m = f.m;
if (m < 0) {
pdf_out(pdf, '-');
m *= -1;
@@ -592,7 +592,7 @@ void print_pdffloat(PDF pdf, pdffloat f)
l = m % ten_pow[e];
if (l != 0) {
pdf_out(pdf, '.');
- j = snprintf(a, 23, "%ld", l + ten_pow[e]);
+ j = snprintf(a, 23, "%d", l + ten_pow[e]);
assert(j < 23);
for (i = e; i > 0; i--) {
if (a[i] != '0')
@@ -791,7 +791,7 @@ void pdf_add_bp(PDF pdf, scaled s)
pdffloat a;
pdfstructure *p = pdf->pstruct;
assert(p != NULL);
- a.m = lround(s * p->k1);
+ a.m = i64round(s * p->k1);
a.e = pdf->decimal_digits;
if (pdf->cave > 0)
pdf_out(pdf, ' ');
@@ -805,9 +805,9 @@ void pdf_add_mag_bp(PDF pdf, scaled s)
pdfstructure *p = pdf->pstruct;
prepare_mag();
if (int_par(mag_code) != 1000)
- a.m = lround(s * (double) int_par(mag_code) / 1000.0 * p->k1);
+ a.m = i64round(s * (double) int_par(mag_code) / 1000.0 * p->k1);
else
- a.m = lround(s * p->k1);
+ a.m = i64round(s * p->k1);
a.e = pdf->decimal_digits;
if (pdf->cave > 0)
pdf_out(pdf, ' ');
diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w b/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w
index 28544b35e76..f1b92379154 100644
--- a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w
+++ b/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w
@@ -33,11 +33,11 @@ static const char _svn_version[] =
#define e_tj 3 /* must be 3; movements in []TJ are in fontsize/$10^3$ units */
@ @c
-static long pdf_char_width(pdfstructure * p, internal_font_number f, int i)
+static int64_t pdf_char_width(pdfstructure * p, internal_font_number f, int i)
{
/* use exactly this formula also for calculating the /Width array values */
return
- lround((double) char_width(f, i) / font_size(f) *
+ i64round((double) char_width(f, i) / font_size(f) *
ten_pow[e_tj + p->cw.e]);
}
@@ -65,7 +65,7 @@ static void setup_fontparameters(PDF pdf, internal_font_number f)
u = font_units_per_em(f) / 1000.0;
pdf->f_cur = f;
p->f_pdf = pdf_set_font(pdf, f);
- p->fs.m = lround(font_size(f) / u / one_bp * ten_pow[p->fs.e]);
+ p->fs.m = i64round(font_size(f) / u / one_bp * ten_pow[p->fs.e]);
slant = font_slant(f) / 1000.0;
extend = font_extend(f) / 1000.0;
expand = 1.0 + font_expand_ratio(f) / 1000.0;
@@ -75,9 +75,9 @@ static void setup_fontparameters(PDF pdf, internal_font_number f)
&& (double) font_size(f) / ten_pow[p->tj_delta.e + e_tj] < 0.5)
p->tj_delta.e--; /* happens for very tiny fonts */
assert(p->cw.e >= p->tj_delta.e); /* else we would need, e. g., |ten_pow[-1]| */
- p->tm[0].m = lround(scale * expand * extend * ten_pow[p->tm[0].e]);
- p->tm[2].m = lround(slant * ten_pow[p->tm[2].e]);
- p->tm[3].m = lround(scale * ten_pow[p->tm[3].e]);
+ p->tm[0].m = i64round(scale * expand * extend * ten_pow[p->tm[0].e]);
+ p->tm[2].m = i64round(slant * ten_pow[p->tm[2].e]);
+ p->tm[3].m = i64round(scale * ten_pow[p->tm[3].e]);
p->k2 =
ten_pow[e_tj +
p->cw.e] * scale / (ten_pow[p->pdf.h.e] * pdf2double(p->fs) *
@@ -222,7 +222,7 @@ void pdf_place_glyph(PDF pdf, internal_font_number f, int c)
&& (p->pdf_bt_pos.v.m + p->tm[5].m) != p->pdf.v.m)
|| (p->wmode == WMODE_V
&& (p->pdf_bt_pos.h.m + p->tm[4].m) != p->pdf.h.m)
- || abs(p->tj_delta.m) >= 1000000) {
+ || p->tj_delta.m >= 1000000 || p->tj_delta.m <= -1000000) {
pdf_goto_textmode(pdf);
set_textmatrix(pdf, pos);
begin_chararray(pdf);
diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfimage.w b/Build/source/texk/web2c/luatexdir/pdf/pdfimage.w
index e787d9674b4..9103cdd1126 100644
--- a/Build/source/texk/web2c/luatexdir/pdf/pdfimage.w
+++ b/Build/source/texk/web2c/luatexdir/pdf/pdfimage.w
@@ -118,10 +118,10 @@ void place_img(PDF pdf, image_dict * idict, scaled_whd dim, int transform)
default:;
}
/* the following is a kludge, TODO: use pdfpage.c functions */
- setpdffloat(cm[0], round(a[0]), r);
- setpdffloat(cm[1], round(a[1]), r);
- setpdffloat(cm[2], round(a[2]), r);
- setpdffloat(cm[3], round(a[3]), r);
+ setpdffloat(cm[0], i64round(a[0]), r);
+ setpdffloat(cm[1], i64round(a[1]), r);
+ setpdffloat(cm[2], i64round(a[2]), r);
+ setpdffloat(cm[3], i64round(a[3]), r);
tmppos.h = round(a[4]);
tmppos.v = round(a[5]);
pdf_goto_pagemode(pdf);
diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfpage.w b/Build/source/texk/web2c/luatexdir/pdf/pdfpage.w
index dbbf8ec667c..1eab44418fe 100644
--- a/Build/source/texk/web2c/luatexdir/pdf/pdfpage.w
+++ b/Build/source/texk/web2c/luatexdir/pdf/pdfpage.w
@@ -105,16 +105,16 @@ boolean calc_pdfpos(pdfstructure * p, scaledpos pos)
boolean move_pdfpos = false;
switch (p->mode) {
case PMODE_PAGE:
- new.h = lround(pos.h * p->k1);
- new.v = lround(pos.v * p->k1);
+ new.h = i32round(pos.h * p->k1);
+ new.v = i32round(pos.v * p->k1);
p->cm[4].m = new.h - p->pdf.h.m; /* cm is concatenated */
p->cm[5].m = new.v - p->pdf.v.m;
if (new.h != p->pdf.h.m || new.v != p->pdf.v.m)
move_pdfpos = true;
break;
case PMODE_TEXT:
- new.h = lround(pos.h * p->k1);
- new.v = lround(pos.v * p->k1);
+ new.h = i32round(pos.h * p->k1);
+ new.v = i32round(pos.v * p->k1);
p->tm[4].m = new.h - p->pdf_bt_pos.h.m; /* Tm replaces */
p->tm[5].m = new.v - p->pdf_bt_pos.v.m;
if (new.h != p->pdf.h.m || new.v != p->pdf.v.m)
@@ -125,9 +125,9 @@ boolean calc_pdfpos(pdfstructure * p, scaledpos pos)
switch (p->wmode) {
case WMODE_H:
new.h =
- lround((pos.h * p->k1 - (double) p->pdf_tj_pos.h.m) * p->k2);
- new.v = lround(pos.v * p->k1);
- p->tj_delta.m = -lround((double)
+ i32round((pos.h * p->k1 - (double) p->pdf_tj_pos.h.m) * p->k2);
+ new.v = i32round(pos.v * p->k1);
+ p->tj_delta.m = -i32round((double)
((new.h - p->cw.m) / ten_pow[p->cw.e -
p->tj_delta.
e]));
@@ -136,11 +136,11 @@ boolean calc_pdfpos(pdfstructure * p, scaledpos pos)
move_pdfpos = true;
break;
case WMODE_V:
- new.h = lround(pos.h * p->k1);
+ new.h = i32round(pos.h * p->k1);
new.v =
- lround(((double) p->pdf_tj_pos.v.m - pos.v * p->k1) * p->k2);
+ i32round(((double) p->pdf_tj_pos.v.m - pos.v * p->k1) * p->k2);
p->tm[4].m = new.h - p->pdf_bt_pos.h.m; /* p->tm[5] is meaningless */
- p->tj_delta.m = -lround((double)
+ p->tj_delta.m = -i32round((double)
((new.v - p->cw.m) / ten_pow[p->cw.e -
p->tj_delta.
e]));
diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfrule.w b/Build/source/texk/web2c/luatexdir/pdf/pdfrule.w
index c720ab2e59d..a73aa57484f 100644
--- a/Build/source/texk/web2c/luatexdir/pdf/pdfrule.w
+++ b/Build/source/texk/web2c/luatexdir/pdf/pdfrule.w
@@ -33,13 +33,13 @@ void pdf_place_rule(PDF pdf, halfword q, scaledpos size)
scaledpos pos = pdf->posstruct->pos;
(void) q;
pdf_goto_pagemode(pdf);
- dim.h.m = lround(size.h * p->k1);
+ dim.h.m = i64round(size.h * p->k1);
dim.h.e = p->pdf.h.e;
- dim.v.m = lround(size.v * p->k1);
+ dim.v.m = i64round(size.v * p->k1);
dim.v.e = p->pdf.v.e;
pdf_puts(pdf, "q\n");
if (size.v <= one_bp) {
- pos.v += (int) lround(0.5 * size.v);
+ pos.v += i32round(0.5 * size.v);
pdf_set_pos_temp(pdf, pos);
pdf_puts(pdf, "[]0 d 0 J ");
print_pdffloat(pdf, dim.v);
@@ -47,7 +47,7 @@ void pdf_place_rule(PDF pdf, halfword q, scaledpos size)
print_pdffloat(pdf, dim.h);
pdf_puts(pdf, " 0 l S\n");
} else if (size.h <= one_bp) {
- pos.h += (int) lround(0.5 * size.h);
+ pos.h += i32round(0.5 * size.h);
pdf_set_pos_temp(pdf, pos);
pdf_puts(pdf, "[]0 d 0 J ");
print_pdffloat(pdf, dim.h);
diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h b/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h
index 981764010fd..d1ae3ee532c 100644
--- a/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h
+++ b/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h
@@ -33,7 +33,8 @@
# define pdfkeyprefix "PTEX"
-# define lround(a) (long) floor((a) + 0.5)
+# define i32round(a) (int) floor((a) + 0.5)
+# define i64round(a) (int64_t) floor((a) + 0.5)
# define MAX_OBJ_COMPRESS_LEVEL 3 /* maximum/clipping value for \pdfobjcompresslevel */
# define OBJSTM_UNSET -1 /* initial value */
@@ -66,7 +67,7 @@ the types explicitly defined in this header, and stay away from types like
*/
typedef struct {
- long m; /* mantissa (significand) */
+ int64_t m; /* mantissa (significand) */
int e; /* exponent * -1 */
} pdffloat;