PDA

View Full Version : Phorum + LargeStringBuilderValue


domdorn
05-23-2010, 05:00 PM
Hi,

I have a forum software installed, called phorum. In quite large threads, quercus throws an exception.

Its complaining about:

Exception File: LargeStringBuilderValue.java
Exception Line: 769

which is the following code in quercus:

private void ensureCapacity(int newCapacity)
{
if (newCapacity > 10000000) {
Thread.dumpStack();
throw new IllegalStateException(); // thats 769
}


is there a reason why the capacity is locked to that particular value?

thanks,
dominik

domdorn
05-25-2010, 11:34 AM
Ok, the problem seems, that the phorum software is poorly written, creating Strings by far greater than 1 000 000 bytes (one time 1 400 000 bytes, sometimes over 2 000 000 bytes)

If I raise the limit to 10 000 000 bytes, I get a OutOfMemoryException.

I'm not sure what I can do about this. Most of the forum posts work, but some (the quite large ones), don't.

Any help would be greatly appreciated.

sblommers
06-03-2010, 12:17 AM
What's you memory_limit (php.ini setting)? What version of Quercus are you using?

Best regards,
Sebastiaan

domdorn
06-04-2010, 11:40 AM
thank you, but raising memory_limit didn't help either (its now 32M).

I'm receiving the following stack trace
[#|2010-06-04T13:37:44.256+0200|SEVERE|glassfish3.0|javax.ent erprise.system.std.com.sun.enterprise.v3.services. impl|_ThreadID=24;_ThreadName=http-thread-pool-8080-(3);|java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1223)
at com.caucho.quercus.env.LargeStringBuilderValue.ens ureCapacity(LargeStringBuilderValue.java:768)
at com.caucho.quercus.env.LargeStringBuilderValue.app end(LargeStringBuilderValue.java:525)
at com.caucho.quercus.env.StringBuilderValue.appendTo (StringBuilderValue.java:596)
at com.caucho.quercus.env.LargeStringBuilderValue.<init>(LargeStringBuilderValue.java:72)
at com.caucho.quercus.env.StringBuilderValue.toString Builder(StringBuilderValue.java:1036)
at com.caucho.quercus.expr.BinaryAppendExpr.eval(Bina ryAppendExpr.java:88)
at com.caucho.quercus.expr.Expr.evalCopy(Expr.java:49 7)
at com.caucho.quercus.expr.BinaryAssignExpr.eval(Bina ryAssignExpr.java:88)
at com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
at com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
at com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:81)
at com.caucho.quercus.statement.ForeachStatement.exec ute(ForeachStatement.java:103)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.program.Function.callImpl(Funct ion.java:431)
at com.caucho.quercus.program.Function.call(Function. java:349)
at com.caucho.quercus.expr.CallExpr.evalImpl(CallExpr .java:236)
at com.caucho.quercus.expr.CallExpr.evalCopy(CallExpr .java:164)
at com.caucho.quercus.expr.BinaryAssignExpr.eval(Bina ryAssignExpr.java:88)
at com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
at com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:81)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.statement.ForeachStatement.exec ute(ForeachStatement.java:186)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.program.Function.callImpl(Funct ion.java:431)
at com.caucho.quercus.program.Function.call(Function. java:349)
at com.caucho.quercus.env.CallbackFunction.call(Callb ackFunction.java:171)
at com.caucho.quercus.lib.FunctionModule.call_user_fu nc_array(FunctionModule.java:101)
at sun.reflect.GeneratedMethodAccessor108.invoke(Unkn own Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.caucho.quercus.module.StaticFunction.invoke(St aticFunction.java:135)
at com.caucho.quercus.env.JavaInvoker.callMethod(Java Invoker.java:727)
at com.caucho.quercus.env.JavaInvoker.call(JavaInvoke r.java:641)
at com.caucho.quercus.expr.CallExpr.evalImpl(CallExpr .java:236)
at com.caucho.quercus.expr.CallExpr.evalCopy(CallExpr .java:164)
at com.caucho.quercus.expr.BinaryAssignExpr.eval(Bina ryAssignExpr.java:88)
at com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
at com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
at com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:81)
at com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:81)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.statement.ForeachStatement.exec ute(ForeachStatement.java:103)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:81)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.program.Function.callImpl(Funct ion.java:431)
at com.caucho.quercus.program.Function.call(Function. java:349)
at com.caucho.quercus.expr.CallExpr.evalImpl(CallExpr .java:236)
at com.caucho.quercus.expr.CallExpr.evalCopy(CallExpr .java:164)
at com.caucho.quercus.expr.BinaryAssignExpr.eval(Bina ryAssignExpr.java:88)
at com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
at com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
at com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:81)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.program.Function.callImpl(Funct ion.java:431)
at com.caucho.quercus.program.Function.call(Function. java:349)
at com.caucho.quercus.expr.CallExpr.evalImpl(CallExpr .java:236)
at com.caucho.quercus.expr.CallExpr.evalCopy(CallExpr .java:164)
at com.caucho.quercus.expr.BinaryAssignExpr.eval(Bina ryAssignExpr.java:88)
at com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
at com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:81)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.program.QuercusProgram.execute( QuercusProgram.java:413)
at com.caucho.quercus.page.InterpretedPage.execute(In terpretedPage.java:89)
at com.caucho.quercus.env.Env.executePage(Env.java:38 80)
at com.caucho.quercus.env.Env.include(Env.java:5337)
at com.caucho.quercus.expr.FunIncludeExpr.eval(FunInc ludeExpr.java:87)
at com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
at com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.program.QuercusProgram.execute( QuercusProgram.java:413)
at com.caucho.quercus.page.InterpretedPage.execute(In terpretedPage.java:89)
at com.caucho.quercus.env.Env.executePage(Env.java:38 80)
at com.caucho.quercus.env.Env.include(Env.java:5337)
at com.caucho.quercus.expr.FunIncludeExpr.eval(FunInc ludeExpr.java:87)
at com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
at com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
at com.caucho.quercus.statement.TryStatement.execute( TryStatement.java:71)
at com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:81)
at com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
at com.caucho.quercus.program.QuercusProgram.execute( QuercusProgram.java:413)
at com.caucho.quercus.page.InterpretedPage.execute(In terpretedPage.java:89)
at com.caucho.quercus.env.Env.executePageTop(Env.java :3891)
at com.caucho.quercus.env.Env.executeTop(Env.java:383 4)
at com.caucho.quercus.servlet.QuercusServletImpl.serv ice(QuercusServletImpl.java:188)
at com.caucho.quercus.servlet.QuercusServlet.service( QuercusServlet.java:582)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:847)
at org.apache.catalina.core.StandardWrapper.service(S tandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:215)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFil ter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationDispatcher.doI nvoke(ApplicationDispatcher.java:820)
at org.apache.catalina.core.ApplicationDispatcher.inv oke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.pro cessRequest(ApplicationDispatcher.java:517)
at org.apache.catalina.core.ApplicationDispatcher.doD ispatch(ApplicationDispatcher.java:488)
at org.apache.catalina.core.ApplicationDispatcher.dis patch(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.dis patch(ApplicationDispatcher.java:336)
at org.apache.catalina.core.ApplicationDispatcher.for ward(ApplicationDispatcher.java:314)
at org.tuckey.web.filters.urlrewrite.RewrittenUrl.doR ewrite(RewrittenUrl.java:176)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter .doFilter(UrlRewriteFilter.java:728)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:256)
at org.apache.cat|#]


I'm running Quercus 4.0.7

sblommers
06-04-2010, 12:51 PM
As soon as I've got some time on my hands I'll test this for you and maybe track the bug. I'll post here when I know more.

Best regards,
Sebastiaan

domdorn
06-14-2010, 06:12 PM
Ok, I found a "workaround" around the issue. One of the "modules" of the forum software "phorum" seems to have a bug which results in a infinite loop creating a too big string resulting in the Exception.

the code actually responsible is this method:

function bbcode_url_handler($content, $args)
{
global $PHORUM;

// Setup special URL options.
static $extratags = NULL;
static $show_full_urls = FALSE;
if ($extratags === NULL)
{
$extratags = '';
$settings = $PHORUM['mod_bbcode'];
if (!empty($settings['links_in_new_window'])) {
$extratags .= 'target="_blank" ';
}
if (!empty($settings['rel_no_follow'])) {
$extratags .= 'rel="nofollow" ';
}
if (!empty($settings['show_full_urls'])) {
$show_full_urls = TRUE;
}
}

$strip_url = FALSE;
if ($args['url'] == '') {
if (strpos($content, '<') !== FALSE ||
strpos($content, '"') !== FALSE ||
strpos($content, '>') !== FALSE)
$content = preg_replace('/[<">].*[<">]/', '', $content);
$args['url'] = $content;
$strip_url = TRUE;
}
if (!preg_match('!^\w+://!', $args['url'])) {
$args['url'] = 'http://'.$args['url'];
}
if ($strip_url && !$show_full_urls) {
$parts = @parse_url($args['url']);
return "[<a href=\"{$args['url']}\" $extratags>{$parts['host']}</a>]";
} else {
return "<a href=\"{$args['url']}\" $extratags>$content</a>";
}
}



if I comment out the line
$extratags .= 'rel="nofollow" ';
it works for some reason. So I think that maybe the preg_replace has a problem with quotes.
However, I wasn't yet able to create a unit test for this.