Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
cordova-android-7.0.0
-
None
-
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:
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
- links to