sourcify icon indicating copy to clipboard operation
sourcify copied to clipboard

Upload from Windows machines can not be processed properly

Open xiaohanzhu opened this issue 2 years ago • 7 comments

This is an issue that keeps coming back. On the sourcify frontend, if we upload a json file or zip file from Windows machines, it will complain "Metadata files missing". If we upload the same file from Mac, everything works fine. If we use API to upload a file, the bug will not be triggered. However if we upload a zip file with a directory structure from Windows, the API will complain can not find the file after we select the contract.

xiaohanzhu avatar Sep 01 '22 22:09 xiaohanzhu

Is it exactly the same file or a Windows formatted file? Can you maybe share them?

I will get my hands on a Windows machine next week and will update you.

kuzdogan avatar Sep 02 '22 13:09 kuzdogan

correct. The file is the same. The only difference is uploading from Windows 11 (chrome/edge) vs MacOS (Safari).
contracts.zip

xiaohanzhu avatar Sep 02 '22 14:09 xiaohanzhu

I was able to pin down the issue to a problem with the zip library adm-zip we are using.

On the Windows machine, when reading the header at zipFile.js line 50, the mainHeader.offset returns an unusually large index in comparison to Unix machines (71041024 vs 1084 for this repo as zip)

This can have something to do with the Windows style line ends: https://stackoverflow.com/a/3831473/6528944

Will look further but it seems we might need to change the zip library we are using, hoping it will resolve the issue. Also while on it, there's no need to write the files and read them back. We can do all of these in-memory.

kuzdogan avatar Sep 19 '22 13:09 kuzdogan

Is the zipFile.js running in the frontend or backend? If we upload a zip file with directory structures through the API, the same issue will happen, although zip file without directory structure works for API

xiaohanzhu avatar Sep 21 '22 20:09 xiaohanzhu

It is running on the backend. That's good and interesting info and I'll add that in the bug report. But we'll likely replace adm-zip completely. Thanks.

kuzdogan avatar Sep 22 '22 08:09 kuzdogan

The issue seems to persist on the jszip library as well. Similarly the error is on reading directories at https://github.com/Stuk/jszip/blob/eaacc682fad834b1e280b58a728704b216c74510/lib/zipEntries.js#L156 not reading files. What really weird is I can't find any issues on Windows machines related to this, which I presume should be prevalent.

kuzdogan avatar Sep 22 '22 16:09 kuzdogan

one more piece of information that maybe useful. The contents of the zip file were created on a Linux vm instead of windows.

xiaohanzhu avatar Sep 22 '22 18:09 xiaohanzhu

Turns out the issue was simpler. Windows was sending a different MIME type we were not checking https://github.com/ethereum/sourcify/commit/92d864d5a3ea1b35ebe29bbf83b5f9cdbe92fbaf

kuzdogan avatar Sep 23 '22 12:09 kuzdogan

It's released, can you please check?

kuzdogan avatar Sep 26 '22 09:09 kuzdogan

Yes all good now

xiaohanzhu avatar Sep 26 '22 23:09 xiaohanzhu