locked
Catastrophic failure (not my words) when copying stream in Win8 RP.

    Question

  • I have this bit of code which just copies a blob to a file:

    return file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(function (output) {
    	var input = blob.msDetachStream();
    	return Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(function () {
    		output.flushAsync().then(function () {
    			input.close();
    			output.close();
    			complete();
    		})
    	}).then(null, function (err) { error(err);});
    });

    This used to work perfectly well in Consumer Preview. Unfortunately in Win8 RP I get the following error:

    0x8000ffff - JavaScript runtime error: Catastrophic failure

    This seems to happen whenever the input stream is larger than 64KB. I couldn't find any hint that something changed about this function in the migration guide: http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/d573295e-926f-4a03-a158-19d4b53521f8

    This issue pretty much breaks our entire app on Win8 RP :/

    Any idea how to fix this?






    Tuesday, June 5, 2012 1:47 AM

Answers

  • Closing this thread.  Partrick was able to give me a simple example using the zip library.  I was able to then construct a repro to isolate this without the zip library.  The issue is the stream retrieved from the blob after you construct a blob with append.  This is a bug in the current release.  This bug should be fixed in a future release.  If you require compression in an application today you can create a C# winmd object and include it in your project that handles zip entries or you can resort to compressing only single files.  Alternately the zip library could be modified to run only on Windows 8 and utilize streams instead of blobs.

    -Jeff


    Jeff Sanders (MSFT)

    Friday, July 6, 2012 6:49 PM
    Moderator

All replies

  • here's the thing..

    I created a way to zip multiple files into a single file and it worked pretty well in the Consumer Preview BUT now with the RC it doesn't work with files largers than ~60KB.

    I did two tests using the Windows 8 Release:

    FIRST TEST:

    I zipped 6 files in a total of 59.8KB

    WORKED PRETTY WELL my app created the .zip file without any problem.

    Second Test:

    I Zipped the same 6 files PLUS a copy of one of the files (so the file is ok and the code should be abble to zip it) so it's 7 files in a total of 65.8KB

    DIDN'T WORK. the result was an empty broken .zip FILE

    ----

    Also, if i try larger files the empty .zip file isn't even created.

    There's nothing wrong with my code. It was working normally in the Consumer version. Works even with webpages because it's a javascript. So PLEASE i need some help here from microsoft people. 

    Is it a BUG from Windows 8? I gotta know before i take a step further.

    Best regards,

    Alan.

    Tuesday, June 5, 2012 4:37 AM
  • EXACTLY.. im experiencing the same problem.. this is my post: http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/0a1724aa-d366-49fc-8399-0a580590ec04

    yes.. anything larger than 64KB doesn't work..

    It HAS to be a bug of the windows and not from the code.

    PLEASE if you get any fix for this.. tell me.

    Tuesday, June 5, 2012 4:40 AM
  • nobody to help?
    Tuesday, June 5, 2012 8:04 PM
  • Hi Alan,

    This is the first I have heard of this.  Can you place a simple repro on SkyDrive or get me a repro via email?

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, June 5, 2012 8:18 PM
    Moderator
  • Hi Patrick,

    This is the first I have heard of this.  Can you place a simple repro on SkyDrive or get me a repro via email?

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, June 5, 2012 8:18 PM
    Moderator
  • did Patrick sent you more details? Any fix for this? is it a related bug?
    Wednesday, June 6, 2012 3:31 AM
  • actually i think the code you posted up here pretty much says everything.. Jeff could just test it himself... It has to be a bug because it was working on Windows Consumer.. i don't know about you but all features i programed, even those that i didn't have to migrate, are working way worse than when i was using the Windows Consumer..
    From the Developer Preview to the Consumer everything i coded got way better.. but with the Release.. even without any error everything seem like pooly running..and im using the same code without any changes.. just some little changes i had to make because of the migration .. but just a few little adjustments..
    nothing really different..

    Anyway.. my app was ready to be submited and now because of this specific bug i can't send it to the Store.. I'm gonna have to wait until it's fixed because there's nothing wrong at all in the code.. it has to be a bug.. the code you posted here show it all... there's nothing wrong with it but it doesn't work with files larger than 64KB..
    well.. i'll be waiting..
    Wednesday, June 6, 2012 5:01 AM
  • Okay, I've just completed a simple test app that opens a file (via file picker) then converts to blob and saves the same (via save file picker) to another file. Works fine regardless of the file size so obviously we are both running into a special case.

    In my own app I get this problem also when trying to read/write a zip file. Maybe this only occurs with the zip library that we use. Alan, what zip mechanism are you using?

    I'm using

    http://gildas-lormeau.github.com/zip.js/

    I will try to get a repro with the zip library. Obviously something must have changed since this used to work in Consumer Preview.

    Wednesday, June 6, 2012 6:18 AM
  • @Jeff:

    Here is a repro:

    https://skydrive.live.com/redir?resid=7558A2B043D1E846!136&authkey=!AF_YeHPuB-4CI9U

    Set a breakpoint at line 157 in default.js

    Run the app.

    The app will prompt you to open a zip. Open the 64ktest.zip file.

    The app then tries to extract the file to the local app folder. Sorry for the nested calls but since *every* IO operation is asynchronous and I need to create the entire folder structure manually I can't make it any simpler.

    Breakpoint will break with Catastrophic failure at line 157. This only happens if entry is larger than 64K



    Wednesday, June 6, 2012 6:46 AM
  • Alan,

    What Zip library are you using.

    You said I could repro this myself.  I cannot.  Did you try to repro without using a zip library?

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, June 6, 2012 12:56 PM
    Moderator
  • Thanks Patrick,

    I was able to repro with your code.  I think it is related to the library code but I am having difficulty following the logic in that library.  Have you contacted the author?  Have you tried to repro with just a large file and blog (I did and could not get a failure).

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, June 6, 2012 12:58 PM
    Moderator
  • Hi Alan,

    I did try this myself and got no error.  That is why it is imporant to get a repro of this issue.  Since it seems to be a 3rd party library you would be best served by engaging that third party for a resolution since they understand their code base much better than you or I do.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, June 6, 2012 8:07 PM
    Moderator
  • But why did it work with Windows Consumer and not with the Release knowing the lib doesn't use anything that have changed with the migration?

    I'm using the exactly the same lib patrick is using..

    And i been testing the .zip lib and analysing step by step and i realized it worked the exactly same way creating the blob when it was small than 64KB and larger than 64KB, so i assumed the lib is ok and then i tested this code from "Using a Blob to save and load content sample": 

     function writeBlobToFile(blob) { 
     
            var filename = document.getElementById("fileName").value; 
            // Open the picker to create a file to save the blob 
            Windows.Storage.KnownFolders.picturesLibrary.createFileAsync(filename, Windows.Storage.CreationCollisionOption.generateUniqueName).then(function (file) { 
                // Open the returned file in order to copy the data 
                file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(function (output) { 
     
                    // Get the IInputStream stream from the blob object 
                    var input = blob.msDetachStream(); 
     
                    // Copy the stream from the blob to the File stream 
                    Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(function () { 
                        output.flushAsync().done(function () { 
                            input.close(); 
                            output.close(); 
                            WinJS.log && WinJS.log("File '" + file.name + "' saved successfully to the Pictures Library!""sample""status"); 
                        }, BlobSample.asyncError); 
                    }, BlobSample.asyncError); 
                }, BlobSample.asyncError); 
            }, BlobSample.asyncError); 
        } 


    calling writeBlobToFile(blob) and the "blob" was created by the .zip lib and as expected less than 64KB worked and larger didn't, throwing the error

    0x8000ffff - JavaScript runtime error: Catastrophic failure


    BUT WHAT IS INTERESTING is the IF i do THIS:

    function writeBlobToFile(blob) {  
            var filename = document.getElementById("fileName").value; 
            // Open the picker to create a file to save the blob 
            Windows.Storage.KnownFolders.picturesLibrary.createFileAsync(filename, Windows.Storage.CreationCollisionOption.generateUniqueName).then(function (file) { 
                // Open the returned file in order to copy the data 
                file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(function (output) {  
                    // Get the IInputStream stream from the blob object 
                    var input = blob.msDetachStream();  
                    // Copy the stream from the blob to the File stream WAS DELETED                 
                }, BlobSample.asyncError); 
            }, BlobSample.asyncError); 
        } 

    The "Catastrofic Failure" error is not thrown. Which tells us that actually the error is related to the Windows 8 function Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output)
    Am i wrong here?






    • Edited by AlansPower Wednesday, June 6, 2012 9:57 PM typo
    Wednesday, June 6, 2012 9:54 PM
  • BTW .. why is it proposed as answered when it's not an issue with the third party lib? If it was WHY it was working in the consumer and NOT with the release? how's that possible without being something related TO the new version of windows and NOT to the lib?


    • Edited by AlansPower Wednesday, June 6, 2012 10:11 PM typo
    Wednesday, June 6, 2012 10:07 PM
  • Alan, 

    yes, the error occurs on the line

      Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output)

    but this doesn't mean that the method is the cause of the problem. Since this method works fine with other streams that are not from the zip library I assume that the problem is somewhere where the zip stream is being processed.

    Since this used to work in Consumer Preview I assume that some change in IE10 causes this issue.

    Wednesday, June 6, 2012 11:09 PM
  • So INDEED it is related to the Windows not just the .zip lib. There's no guarantee any change in the .zip lib can fix it if we don't even know what changed in the IE10/Wind RC that is causing it to crash ONLY when it's larger than 64KB.
    Wednesday, June 6, 2012 11:37 PM
  • I agree. Have you been able to figure out where exactly the issue occurs in the zip library? I can't seem to find it.

    Also, since you said you are using it on a normal web page as well, have you tried this in IE10?

    Thursday, June 7, 2012 12:28 AM
  • the first error occurs after the function createZipWriter is called but it's not an issue inside this function. i had to spread lots of "console.log()" through out the code to track it.. but you can't isolate it to find exactly where (i tried) because, as i've been saying, it's not exactly an issue with the lib but something the windows is not working very well AS it was before the Release.

    And what's interesting is that the onerror is thrown BUT after that the lib keeps running normally compressing every single file and creating the Blob.

    is the BlobBuilder in the new Windows Release really working the same way?

    ---> var BlobBuilder = obj.WebKitBlobBuilder || obj.MozBlobBuilder || obj.MSBlobBuilder || obj.BlobBuilder;

    and i didn't test with the IE10, but i bet it's not working in the release version either.

    Patrick could you please set this Thread as NOT answered?

    Thursday, June 7, 2012 3:10 AM
  • yes, of course. I hadn't actually accepted it as an answer yet anyway.

    I sat down today and tested the lib and I agree that there must be something going inside the framework itself.



    Thursday, June 7, 2012 3:14 AM
  • my app depends on that.. my app should've been submited last week. and because of that i can't do it. 
    Thursday, June 7, 2012 3:24 AM
  • anyone? ...
    Thursday, June 7, 2012 5:35 PM
  • Patrick i contacted the developer of the zip.js and he even tested on IE10 and everything worked just fine. There's nothing wrong in the Lib according to him.

    Is there any chance the BlobBuilder from Microsoft is not working very well?

    Thursday, June 7, 2012 7:20 PM
  • @Jeff: could you please escalate this issue. We are not able to solve it by ourselves.
    Thursday, June 7, 2012 10:59 PM
  • Here's something microsof people should take a look at.. 

    the ArrayBuffer  or the UInt8Array is probably buggy in the new version of windows (RC)

    Thursday, June 7, 2012 11:32 PM
  • or the BlobBuiler.. we been testing.. we know it's one of them: BlobBuiler, ArrayBuffer  or the UInt8Array
    Thursday, June 7, 2012 11:38 PM
  • ok.. now we can prove it's something wrong with the microsoft framework .. in the stream..
    because after we created the Blob with the zip.js we showed the blob.size and the size IS OKAY.. the right size.. and then as you know it doesn't crash until we call something from microsoft api..

     this is a proof that stream are buggy
    zip.js can provoke this type of bug
    it's impossible
    if it was possible, then it would be a failure
    a js program should NEVER be able to do a crash

    from a security point of view, it is quite dangerous

    Friday, June 8, 2012 12:14 AM
  • "maybe" BlobBuiler, ArrayBuffer  or the UInt8Array might be a side effect but the blob created by the zip.js is JUST FINE as it should be.. it's even working using IE10 on desktop.. so there's no way it's a problem with the lib.. 
    Friday, June 8, 2012 12:16 AM
  • that's great testing, thanks. I'm sure that with this info and the repro code they will be able to find the issue.
    Friday, June 8, 2012 12:17 AM
  • i hope they do it fast.. because i wanted my app in their store as soon as possible.. i already got a damn developer from a company trying to steal my design.. he was even watching videos of our old demo and they are trying to develpe the exact same app i am developing.. damnit.. lol

    TIME IS MONEY!

    Friday, June 8, 2012 12:20 AM
  • ... ?
    Friday, June 8, 2012 2:56 PM
  • Hi Patrick,

    I am the escalation.

    I will look at this issue later today.  You were still not able to isolate which of the calls in the library is at the root of this correct?  I suspect the blob somewhere because you can follow the stream bits as they unwind.

    This will take some time because I need to isolate exactly which API may be involved.  I will keep you informed of what I find!

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, June 12, 2012 2:32 PM
    Moderator
  • Hi Alan,

    It appears the blob created by the zip library is not complete.  Can you put me in contact with the author of the library owner and see if he is interested in fixing the library to work with the Release Preview?

    Thanks!

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, June 12, 2012 7:46 PM
    Moderator
  • Hi Jeff,

    Thanks for looking into this.

    Did Alan provide you with the contact details?

    Patrick

    Friday, June 15, 2012 12:47 AM
  • Hi Patrick,

    No he did not.  Do you have more information about the author and can you engage him?  I would be happy to work directly with the author on this if he is interested in resolving this!

    -Jeff


    Jeff Sanders (MSFT)

    Friday, June 15, 2012 12:14 PM
    Moderator
  • Closing this thread.  Partrick was able to give me a simple example using the zip library.  I was able to then construct a repro to isolate this without the zip library.  The issue is the stream retrieved from the blob after you construct a blob with append.  This is a bug in the current release.  This bug should be fixed in a future release.  If you require compression in an application today you can create a C# winmd object and include it in your project that handles zip entries or you can resort to compressing only single files.  Alternately the zip library could be modified to run only on Windows 8 and utilize streams instead of blobs.

    -Jeff


    Jeff Sanders (MSFT)

    Friday, July 6, 2012 6:49 PM
    Moderator