mraible commented on code in PR #317:
URL: https://github.com/apache/roller/pull/317#discussion_r4609099987


##########
app/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RenderLimitUberspector.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.roller.weblogger.ui.rendering.velocity;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.util.introspection.AbstractChainableUberspector;
+import org.apache.velocity.util.introspection.Info;
+import org.apache.velocity.util.introspection.VelMethod;
+import org.apache.velocity.util.introspection.VelPropertyGet;
+
+/**
+ * Chained after SecureUberspector, this keeps method calls from templates
+ * inside the render limits: each call and property read checks the deadline,
+ * a string a call returns may be no longer than the output limit, and
+ * String.repeat, which can build a huge string in one call, is not offered.
+ */
+public class RenderLimitUberspector extends AbstractChainableUberspector {
+
+    private static final Log LOG = 
LogFactory.getLog(RenderLimitUberspector.class);
+
+    @Override
+    public Iterator getIterator(Object obj, Info i) {
+        RenderSession.checkDeadline();
+        return super.getIterator(obj, i);
+    }
+
+    @Override
+    public VelMethod getMethod(Object obj, String methodName, Object[] args, 
Info i) {
+        if (obj instanceof String && "repeat".equals(methodName)) {

Review Comment:
   String calls that can grow a string (replace, concat, 
toUpperCase/toLowerCase, $utils.replace, StringBuilder/StringBuffer growth) now 
work out the longest result before they run and stop the render with the output 
limit error when it is over; replaceAll and replaceFirst check the limit before 
each replacement, and format, formatted, join and indent aren't offered, like 
repeat. RenderLimitsTest measures the render thread's allocation and fails 
without the change (42 MB allocated for one replace), StringGrowthTest compares 
each bound with real results on small strings, and ordinary replaces still 
render.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to