Test for recursive macro definitions by keeping a substitution count and also checking the size of the string after substitution

This commit is contained in:
Davide P. Cervone 2011-01-04 11:15:54 -05:00
parent 58ce73bfd8
commit a9b754c811
2 changed files with 11 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -915,7 +915,7 @@
var PARSE = MathJax.Object.Subclass({
Init: function (string,env) {
this.string = string; this.i = 0;
this.string = string; this.i = 0; this.macroCount = 0;
var ENV; if (env) {ENV = {}; for (var id in env) {if (env.hasOwnProperty(id)) {ENV[id] = env[id]}}}
this.stack = TEX.Stack(ENV);
this.Parse();
@ -1357,6 +1357,8 @@
}
this.string = this.AddArgs(macro,this.string.slice(this.i));
this.i = 0;
if (++this.macroCount > TEX.config.MAXMACROS)
{TEX.Error("MathJax maximum macro substitution count exceeded; is there a recursive macro call?")}
},
Matrix: function (name,open,close,align,spacing,vspacing,style) {
@ -1679,6 +1681,8 @@
*/
AddArgs: function (s1,s2) {
if (s2.match(/^[a-z]/i) && s1.match(/(^|[^\\])(\\\\)*\\[a-z]+$/i)) {s1 += ' '}
if (s1.length + s2.length > TEX.config.MAXBUFFER)
{TEX.Error("MathJax internal buffer size exceeded; is there a recursive macro call?")}
return s1+s2;
}
@ -1689,6 +1693,11 @@
TEX.Augment({
Stack: STACK, Parse: PARSE, Definitions: TEXDEF, Startup: STARTUP,
config: {
MAXMACROS: 10000, // maximum number of macro substitutions per equation
MAXBUFFER: 5*1024 // maximum size of TeX string to process
},
Translate: function (script) {
var mml, math = script.innerHTML.replace(/^\s+/,"").replace(/\s+$/,"");
if (MathJax.Hub.Browser.isKonqueror)