groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8056) GroovyCodeSource(URL) can leak a file handler
Date Sun, 19 Feb 2017 00:26:44 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8056?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15873376#comment-15873376
] 

ASF GitHub Bot commented on GROOVY-8056:
----------------------------------------

GitHub user jwagenleitner opened a pull request:

    https://github.com/apache/groovy/pull/500

    GROOVY-8056: GroovyCodeSource(URL) can leak a file handler

    URLConnect.getContentEncoding returns the Content-Encoding
    HTTP Header [1] which is not a charset.  Since this method would
    have either returned null or an invalid charset, the code path
    specifying the encoding would normally not have been executed.
    The charset may be contained in the Content-Type header, but
    rather than attempt to parse that string which would require
    closing the connection, this fix avoids opening the connection
    and relies on the default charset.
    
    [1] https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/jwagenleitner/groovy groovy8056-content-encoding

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/500.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #500
    
----
commit 29a641ccc212d397bdc11d3a995763b88dfe34b5
Author: John Wagenleitner <jwagenleitner@apache.org>
Date:   2017-02-19T00:22:49Z

    GROOVY-8056: GroovyCodeSource(URL) can leak a file handler
    
    URLConnect.getContentEncoding returns the Content-Encoding
    HTTP Header [1] which is not a charset.  Since this method would
    have either returned null or an invalid charset, the code path
    specifying the encoding would normally not have been executed.
    The charset may be contained in the Content-Type header, but
    rather than attempt to parse that string which would require
    closing the connection, this fix avoids opening the connection
    and relies on the default charset.
    
    [1] https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11

----


> GroovyCodeSource(URL) can leak a file handler
> ---------------------------------------------
>
>                 Key: GROOVY-8056
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8056
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.8
>            Reporter: Andy Wilkinson
>
> When {{GroovyCodeSource}} is created from a {{URL}} it calls {{url.openConnection.getContentEncoding()}}.
When it's a {{file:}} URL, this causes a {{FileInputStream}} to be opened and never closed.
The stack trace for it being opened is:
> {noformat}
> at java.io.FileInputStream.<init>(Unknown Source)
> 	at java.io.FileInputStream.<init>(Unknown Source)
> 	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
> 	at sun.net.www.protocol.file.FileURLConnection.initializeHeaders(Unknown Source)
> 	at sun.net.www.protocol.file.FileURLConnection.getHeaderField(Unknown Source)
> 	at java.net.URLConnection.getContentEncoding(Unknown Source)
> 	at groovy.lang.GroovyCodeSource.<init>(GroovyCodeSource.java:176)
> 	at groovy.text.markup.MarkupTemplateEngine$MarkupTemplateMaker.<init>(MarkupTemplateEngine.java:222)
> 	at groovy.text.markup.MarkupTemplateEngine.createTemplateByPath(MarkupTemplateEngine.java:145)
> {noformat}
> I believe that keeping a local reference to the {{URLConnection}} and then calling {{getInputStream().close()}}
on it will fix the problem.
> For reference [this|https://github.com/spring-projects/spring-boot/issues/7892] is the
Spring Boot issues where the problem was originally reported.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message