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:
parent
58ce73bfd8
commit
a9b754c811
File diff suppressed because one or more lines are too long
|
@ -915,7 +915,7 @@
|
||||||
|
|
||||||
var PARSE = MathJax.Object.Subclass({
|
var PARSE = MathJax.Object.Subclass({
|
||||||
Init: function (string,env) {
|
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]}}}
|
var ENV; if (env) {ENV = {}; for (var id in env) {if (env.hasOwnProperty(id)) {ENV[id] = env[id]}}}
|
||||||
this.stack = TEX.Stack(ENV);
|
this.stack = TEX.Stack(ENV);
|
||||||
this.Parse();
|
this.Parse();
|
||||||
|
@ -1357,6 +1357,8 @@
|
||||||
}
|
}
|
||||||
this.string = this.AddArgs(macro,this.string.slice(this.i));
|
this.string = this.AddArgs(macro,this.string.slice(this.i));
|
||||||
this.i = 0;
|
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) {
|
Matrix: function (name,open,close,align,spacing,vspacing,style) {
|
||||||
|
@ -1679,6 +1681,8 @@
|
||||||
*/
|
*/
|
||||||
AddArgs: function (s1,s2) {
|
AddArgs: function (s1,s2) {
|
||||||
if (s2.match(/^[a-z]/i) && s1.match(/(^|[^\\])(\\\\)*\\[a-z]+$/i)) {s1 += ' '}
|
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;
|
return s1+s2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1689,6 +1693,11 @@
|
||||||
TEX.Augment({
|
TEX.Augment({
|
||||||
Stack: STACK, Parse: PARSE, Definitions: TEXDEF, Startup: STARTUP,
|
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) {
|
Translate: function (script) {
|
||||||
var mml, math = script.innerHTML.replace(/^\s+/,"").replace(/\s+$/,"");
|
var mml, math = script.innerHTML.replace(/^\s+/,"").replace(/\s+$/,"");
|
||||||
if (MathJax.Hub.Browser.isKonqueror)
|
if (MathJax.Hub.Browser.isKonqueror)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user