Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-13923

CordovaResourceApi.java method OpenForReadResult returns a -1 length

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • cordova-android-7.0.0
    • None
    • cordova-android
    • None
    • cordova 8.0.0

      cordova-android 7.0.0

      cordova-plugin-file 6.0.1

    Description

      Here are details to recreate:

      https://github.com/AnthonyWard/cordova-file-plugin-bug

      In cordova-android the CordovaResourceApi.java -> OpenForReadResult method returns a -1 length in certain circumstances.

      This has a knock on effect to the cordova-plugin-file > Filesystem.java > readFileAtURL method, causing file corruption as each chunk effectively has no end.

      There is a possible fix in the plugin cordova-plugin-file already proposed

      https://github.com/apache/cordova-plugin-file/pull/217

      https://issues.apache.org/jira/browse/CB-13245?jql=text%20~%20%22CordovaResourceApi%22

      Or I propose it could be fixed upstream in cordova-android here:

      https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaResourceApi.java

      In the method OpenForReadResult there is one path (in the catch) that leaves the length as -1 causing the defect

      try

      { assetFd = assetManager.openFd(assetPath); inputStream = assetFd.createInputStream(); length = assetFd.getLength(); }

      catch (FileNotFoundException e)

      { // Will occur if the file is compressed. inputStream = assetManager.open(assetPath); }

      Adding length = inputStream.available(); in the catch fixes the issue for me, but I'm not a java developer so can't evaluate if that's a bad idea for another reason.

      Attachments

        Issue Links

          Activity

            People

              bowserj Joey Robert Bowser
              anthony.ward Anthony Ward
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: