Skip to content

FlashMapManager throws StringIndexOutOfBoundsException for empty target URL path #23240

Closed

Description

@pbluong

Hello,

My project is currently using Spring MVC version 5.0.8.

Incidentally, I found a technical error relating to the library.

It is about the method decodeAndNormalizePath of the AbstractFlashMapManager class. If you look at the implementation, you can easily see that it is wrong. An empty path will pass the null check but fail to get the first character.

private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) {
/* 231 */       if(path != null) {
/* 232 */          path = this.getUrlPathHelper().decodeRequestString(request, path);
/* 233 */          if(path.charAt(0) != 47) {
/* 234 */             String requestUri = this.getUrlPathHelper().getRequestUri(request);
/* 235 */             path = requestUri.substring(0, requestUri.lastIndexOf(47) + 1) + path;
/* 236 */             path = StringUtils.cleanPath(path);
/*     */          }      }
/*     */ 
/* 239 */       return path;
/*     */    }
org.apache.catalina.core.ApplicationDispatcher.invoke Servlet.service() for servlet [tnjs-servlet] threw exception
 java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:44)
	at java.base/java.lang.String.charAt(String.java:704)
	at org.springframework.web.servlet.support.AbstractFlashMapManager.decodeAndNormalizePath(AbstractFlashMapManager.java:233)
	at org.springframework.web.servlet.support.AbstractFlashMapManager.saveOutputFlashMap(AbstractFlashMapManager.java:204)
	at org.springframework.web.servlet.support.RequestContextUtils.saveOutputFlashMap(RequestContextUtils.java:281)
	at org.springframework.web.servlet.view.RedirectView.renderMergedOutputModel(RedirectView.java:311)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1325)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

Activity

  1. added
    status: waiting-for-triage
    on Jul 5, 2019
  2. added
    in: web
    type: bug
    and removed
    status: waiting-for-triage
    on Jul 7, 2019
  3. changed the title [-]Technical error when decode and normalize path in flash map manager[/-] [+]FlashMapManager throws StringIndexOutOfBoundsException for empty target URL path[/+] on Jul 7, 2019
  4. sbrannen commented on Jul 7, 2019

    @sbrannen
    Member

    Thanks for raising the issue. We'll look into it.

  5. self-assigned this
    on Jul 7, 2019
  6. added this to the 5.1.9 milestone on Jul 7, 2019
  7. added
    status: backported
    and removed on Jul 7, 2019
  8. added a commit that references this issue on Jul 7, 2019
    db8be50
  9. added 2 commits that reference this issue on Jul 7, 2019
    271885c
    e5a28f8
  10. pbluong commented on Aug 26, 2019

    @pbluong
    Author

    Hello sbrannen,
    Could you deliver the fix in minor releases of Spring 5.0.x?
    Thanks,
    Binh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: backportedtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions