diff options
author | Luigi Scarso <luigi.scarso@gmail.com> | 2019-01-26 14:27:38 +0000 |
---|---|---|
committer | Luigi Scarso <luigi.scarso@gmail.com> | 2019-01-26 14:27:38 +0000 |
commit | 77f296fc4d17c9378658b6085929e839b4f1b9c8 (patch) | |
tree | 1c11ff501a0a4c17e4f3828673f76752190d4c21 /Build/source | |
parent | feaa0906fc851cffb7d9b16f80202ce6e7a8b06e (diff) |
MetaPost: fixed bisection. LuaTeX: updated dev. id.
git-svn-id: svn://tug.org/texlive/trunk@49823 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/luatex_svnversion.h | 2 | ||||
-rw-r--r-- | Build/source/texk/web2c/mplibdir/ChangeLog | 7 | ||||
-rw-r--r-- | Build/source/texk/web2c/mplibdir/mp.w | 45 | ||||
-rw-r--r-- | Build/source/texk/web2c/mplibdir/mpost.w | 19 |
4 files changed, 53 insertions, 20 deletions
diff --git a/Build/source/texk/web2c/luatexdir/luatex_svnversion.h b/Build/source/texk/web2c/luatexdir/luatex_svnversion.h index 4552428c09e..b658a8e9d8d 100644 --- a/Build/source/texk/web2c/luatexdir/luatex_svnversion.h +++ b/Build/source/texk/web2c/luatexdir/luatex_svnversion.h @@ -1 +1 @@ -#define luatex_svn_revision 7056 +#define luatex_svn_revision 7064 diff --git a/Build/source/texk/web2c/mplibdir/ChangeLog b/Build/source/texk/web2c/mplibdir/ChangeLog index 90cedb96783..73cebd69225 100644 --- a/Build/source/texk/web2c/mplibdir/ChangeLog +++ b/Build/source/texk/web2c/mplibdir/ChangeLog @@ -1,3 +1,10 @@ +2019-01-26 Luigi Scarso <luigi.scarso@gmail.com> + * Fixed bisection algorithm (overflow of number of bisections in decimal mode with low precision) + * Added 2 levels to the bisection algorithm for cubic intersection. Need testing. + * Fixed a buffer overflow on command line; for consistency with mp_reallocate_buffer, + now accepting input from command line of at most 0xFFFFFFF bytes. + + 2019-01-06 Luigi Scarso <luigi.scarso@gmail.com> * Added r-mpost as an alias for mpost --restricted diff --git a/Build/source/texk/web2c/mplibdir/mp.w b/Build/source/texk/web2c/mplibdir/mp.w index 2b9bc6c6672..f4acc3d0e06 100644 --- a/Build/source/texk/web2c/mplibdir/mp.w +++ b/Build/source/texk/web2c/mplibdir/mp.w @@ -189,7 +189,7 @@ static int DEBUGENVELOPECOUNTER=0; #include "mpmath.h" /* internal header */ #include "mpmathdouble.h" /* internal header */ #include "mpmathdecimal.h" /* internal header */ -/*#include "mpmathbinary.h"*/ /* internal header */ +/*|#include "mpmathbinary.h"|*/ /* internal header */ #include "mpstrings.h" /* internal header */ /* BEGIN PATCH */ mp_number dx_ap; /* approximation of dx */ @@ -608,7 +608,7 @@ MP mp_initialize (MP_options * opt) { mp_reallocate_paths (mp, 1000); mp_reallocate_fonts (mp, 8); mp->history = mp_fatal_error_stop; /* in case we quit during initialization */ - @<Check the ``constant'' values...@>; + @<Check the ``constant'' values...@>; /* consider also the raise of the bits for precision */ if (mp->bad > 0) { char ss[256]; mp_snprintf (ss, 256, "Ouch---my internal constants have been clobbered!\n" @@ -1333,7 +1333,7 @@ not be typed immediately after~`\.{**}'.) @c boolean mp_init_terminal (MP mp) { /* gets the terminal input started */ - t_open_in(); + t_open_in(); if (mp->last != 0) { loc = 0; mp->first = 0; @@ -15772,18 +15772,23 @@ and |(pp,mp_link(pp))|, respectively. @c static void mp_cubic_intersection (MP mp, mp_knot p, mp_knot pp) { mp_knot q, qq; /* |mp_link(p)|, |mp_link(pp)| */ - mp_number x_two_t; /* increment bit precision by x bit */ + mp_number x_two_t; /* increment bit precision */ + mp_number x_two_t_low_precision; /* check for low precision */ mp->time_to_go = max_patience; set_number_from_scaled (mp->max_t, 2); new_number (x_two_t); + new_number (x_two_t_low_precision); + number_clone (x_two_t,two_t); - number_double(x_two_t); number_double(x_two_t); /* add x=2 bit of precision */ - number_double(x_two_t); + number_double(x_two_t);number_double(x_two_t); /* added 2 bit of precision */ + set_number_from_double (x_two_t_low_precision,-0.5); + number_add (x_two_t_low_precision,x_two_t); + @<Initialize for intersections at level zero@>; CONTINUE: while (1) { /* When we are in arbitrary precision math, low precisions can */ - /* lead to acces locations beyond the stack_size: in this case */ + /* lead to acces locations beyond the |stack_size|: in this case */ /* we say that there is no intersection.*/ if ( ((x_packet (mp->xy))+4)>bistack_size || ((u_packet (mp->uv))+4)>bistack_size || @@ -15793,7 +15798,16 @@ CONTINUE: set_number_from_scaled (mp->cur_tt, 1); goto NOT_FOUND; } - + /* Also, low precision can lead to wrong result in comparing */ + /* so we check that the level of bisection stay low, and later */ + /* we will also check that the bisection level are safe from */ + /* approximations. */ + if (number_greater (mp->max_t, x_two_t)){ + set_number_from_scaled (mp->cur_t, 1); + set_number_from_scaled (mp->cur_tt, 1); + goto NOT_FOUND; + } + if (number_to_scaled (mp->delx) - mp->tol <= number_to_scaled (stack_max (x_packet (mp->xy))) - number_to_scaled (stack_min (u_packet (mp->uv)))) if (number_to_scaled (mp->delx) + mp->tol >= @@ -15803,8 +15817,8 @@ CONTINUE: if (number_to_scaled (mp->dely) + mp->tol >= number_to_scaled (stack_min (y_packet (mp->xy))) - number_to_scaled (stack_max (v_packet (mp->uv)))) { if (number_to_scaled (mp->cur_t) >= number_to_scaled (mp->max_t)) { - if (number_equal(mp->max_t, x_two_t)) { /* we've done 17+x bisections */ - number_divide_int(mp->cur_t,1<<3);number_divide_int(mp->cur_tt,1<<3); + if ( number_equal(mp->max_t, x_two_t) || number_greater(mp->max_t,x_two_t_low_precision)) { /* we've done 17+2 bisections */ + number_divide_int(mp->cur_t,1<<2);number_divide_int(mp->cur_tt,1<<2); /* restore values due bit precision */ set_number_from_scaled (mp->cur_t, ((number_to_scaled (mp->cur_t) + 1)/2)); set_number_from_scaled (mp->cur_tt, ((number_to_scaled (mp->cur_tt) + 1)/2)); return; @@ -15819,7 +15833,8 @@ CONTINUE: if (mp->time_to_go > 0) { decr (mp->time_to_go); } else { - number_divide_int(mp->appr_t,1<<3);number_divide_int(mp->appr_tt,1<<3); + /* we have added 2 bit of precision */ + number_divide_int(mp->appr_t,1<<2);number_divide_int(mp->appr_tt,1<<2); while (number_less (mp->appr_t, unity_t)) { number_double(mp->appr_t); number_double(mp->appr_tt); @@ -20025,10 +20040,10 @@ line and preceded by a space or at the beginning of a line. if (mode <= 0) { txt[size - 1] = ' '; } else if (verb) { - /* modes >= 1 permit a newline in verbatimtex */ + /* modes $\geq 1$ permit a newline in verbatimtex */ txt[size - 1] = '\n'; } else if (mode >= 2) { - /* modes >= 2 permit a newline in btex */ + /* modes $\geq 2$ permit a newline in btex */ txt[size - 1] = '\n'; } else { txt[size - 1] = ' '; @@ -20069,8 +20084,8 @@ line and preceded by a space or at the beginning of a line. txt[size] = '\0'; ptr = txt; } else { - /* strip trailing whitespace, we have a \0 so we're one off */ - /* while ((size > 1) && (mp->char_class[(ASCII_code) txt[size-2]] == space_class || txt[size-2] == '\n')) { */ + /* strip trailing whitespace, we have a |'\0'| so we are off by one */ + /* |while ((size > 1) && (mp->char_class[(ASCII_code) txt[size-2]] == space_class| $\vbv\vbv$ |txt[size-2] == '\n')) | */ while ((size > 1) && (mp->char_class[(ASCII_code) txt[size-1]] == space_class || txt[size-1] == '\n')) { decr(size); } diff --git a/Build/source/texk/web2c/mplibdir/mpost.w b/Build/source/texk/web2c/mplibdir/mpost.w index 3cf35eedb1d..2c8ecf6d03f 100644 --- a/Build/source/texk/web2c/mplibdir/mpost.w +++ b/Build/source/texk/web2c/mplibdir/mpost.w @@ -1102,6 +1102,7 @@ stored in the \MP\ instance, this will be taken as the first line of input. @d command_line_size 256 +@d max_commad_line_size 0xFFFFFFF /* should be the same of |max_halfword| (see |mp_reallocate_buffer|) */ @<Copy the rest of the command line@>= { @@ -1109,18 +1110,28 @@ input. options->command_line = mpost_xmalloc(command_line_size); strcpy(options->command_line,""); if (optind<argc) { + int optind_aux = optind; + size_t buflen = 0; + for(;optind_aux<argc;optind_aux++) { + buflen +=(strlen(argv[optind_aux])+1); /* reserve space for ' ' as separator */ + } + /* Last char is ' ', no need to reserve space for final '\0' */ + if (buflen > max_commad_line_size) { + fprintf(stderr,"length of command line too long!\n"); + exit(EXIT_FAILURE); + } + mpost_xfree(options->command_line); + options->command_line = mpost_xmalloc(buflen); k=0; for(;optind<argc;optind++) { char *c = argv[optind]; while (*c != '\0') { - if (k<(command_line_size-1)) { - options->command_line[k++] = *c; - } + options->command_line[k++] = *c; c++; } options->command_line[k++] = ' '; } - while (k>0) { + while (k>0) { if (options->command_line[(k-1)] == ' ') k--; else |