[ https://issues.apache.org/jira/browse/CB-13245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16154073#comment-16154073 ]
ASF GitHub Bot commented on CB-13245: ------------------------------------- GitHub user Beatinu opened a pull request: https://github.com/apache/cordova-plugin-file/pull/217 CB-13245: (android) Fix bug caused by negative length reported for an asset <!-- Please make sure the checklist boxes are all checked before submitting the PR. The checklist is intended as a quick reference, for complete details please see our Contributor Guidelines: http://cordova.apache.org/contribute/contribute_guidelines.html Thanks! --> ### Platforms affected Android ### What does this PR do? Check the length of CordovaResourceApi.OpenForReadResult in readFileAtURL() to fix loading Android assets with a length greater than FileReader.READ_CHUNK_SIZE. When the length returned is < 0, use InputStream.available() to get the length of compressed assets. ### What testing has been done on this change? Fixes a bug in one of my apps when loading a large .json file into a string. ### Checklist - [X] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database - [X] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected. - [ ] Added automated test coverage as appropriate for this change. You can merge this pull request into a Git repository by running: $ git pull https://github.com/Beatinu/cordova-plugin-file master Alternatively you can review and apply these changes as the patch at: https://github.com/apache/cordova-plugin-file/pull/217.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 #217 ---- commit 63fe1b3a91d029f9105be4e55f6fef7ac6392934 Author: Daniel Behnen <d.beh...@it4process.de> Date: 2017-09-05T17:21:04Z Use input stream length when input length is negative to fix loading compressed assets ---- > Filereader.readAsText fails on Android with long text files when > ---------------------------------------------------------------- > > Key: CB-13245 > URL: https://issues.apache.org/jira/browse/CB-13245 > Project: Apache Cordova > Issue Type: Bug > Components: cordova-plugin-file > Affects Versions: Master > Environment: Android 7.1.1 > Reporter: Daniel Behnen > > When reader.readAsText is called with an URI pointing to a local asset with a > size greater than READ_CHUNK_SIZE = 256 * 1024, loading produces corrupt > data. > The behaviour is caused by a negative length returned by > CordovaResourceApi.openForRead() when the URI is a URI_TYPE_ASSET. Given the > negative length, Filesystem.readFileAtURL() returns the whole file instead of > the desired part and FileReader.readSuccessCallback() does not check the > returned buffer size. Hence, the following chunks are attated to the buffer > regardless of whether the file was already completely read. -- This message was sent by Atlassian JIRA (v6.4.14#64029) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org