snoopdave commented on code in PR #317: URL: https://github.com/apache/roller/pull/317#discussion_r4608441937
########## 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: **Blocking:** `String.replace(CharSequence, CharSequence)` remains callable and can allocate a result beyond `maxOutputChars` before `checked()` sees it. Guard expanding String operations before invocation, or exclude them, and add a regression test with a safe allocation ceiling. -- 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]
