can't find end of central directory #1013

Closed
opened 2018-03-02 06:24:27 +00:00 by wlpeter · 7 comments
wlpeter commented 2018-03-02 06:24:27 +00:00 (Migrated from github.com)

I upload one file which had about ten thousand lines of text, but it throw error. The error is "can't find end of central directory".

ERROR 24471 nodejs.Error: Corrupted zip : can't find end of central directory (uncaughtException throw 1 times on pid:24471)
    at ZipEntries.readEndOfCentral (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/jszip.js:2270:19)
    at ZipEntries.load (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/jszip.js:2332:14)
    at new ZipEntries (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/jszip.js:2156:14)
    at JSZip.module.exports [as load] (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/jszip.js:577:18)
    at new JSZip (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/jszip.js:524:14)
    at read_zip (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/xlsx.js:18863:24)
    at Object.readSync [as read] (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/xlsx.js:18931:69)
    at FileStream.stream.once (/home/servers/api.cloud.nh/app/extend/application.js:200:22)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at FileStream.emit (events.js:208:7)
    at emitReadable_ (_stream_readable.js:513:10)
    at _combinedTickCallback (internal/process/next_tick.js:135:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

I upload one file which had about ten thousand lines of text, but it throw error. The error is "can't find end of central directory". ``` ERROR 24471 nodejs.Error: Corrupted zip : can't find end of central directory (uncaughtException throw 1 times on pid:24471) at ZipEntries.readEndOfCentral (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/jszip.js:2270:19) at ZipEntries.load (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/jszip.js:2332:14) at new ZipEntries (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/jszip.js:2156:14) at JSZip.module.exports [as load] (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/jszip.js:577:18) at new JSZip (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/jszip.js:524:14) at read_zip (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/xlsx.js:18863:24) at Object.readSync [as read] (/home/servers/api.cloud.nh/node_modules/_xlsx@0.11.19@xlsx/xlsx.js:18931:69) at FileStream.stream.once (/home/servers/api.cloud.nh/app/extend/application.js:200:22) at Object.onceWrapper (events.js:313:30) at emitNone (events.js:106:13) at FileStream.emit (events.js:208:7) at emitReadable_ (_stream_readable.js:513:10) at _combinedTickCallback (internal/process/next_tick.js:135:11) at process._tickCallback (internal/process/next_tick.js:180:9) ```
SheetJSDev commented 2018-03-02 06:41:32 +00:00 (Migrated from github.com)

@wlpeter This is reproducible with leading characters PK followed by two tab characters:

require('xlsx').read("PK\t\t123", {type:"binary"})

The fix is in bits/87_read.js:

-               case 0x50: if(n[1] === 0x4B && n[2] < 0x20 && n[3] < 0x20) return read_zip(d, o); break;
+               case 0x50: return (n[1] === 0x4B && n[2] < 0x09 && n[3] < 0x09) ? read_zip(d, o) : read_prn(data, d, o, str); break;
@wlpeter This is reproducible with leading characters `PK` followed by two tab characters: ```js require('xlsx').read("PK\t\t123", {type:"binary"}) ``` The fix is in `bits/87_read.js`: ```diff - case 0x50: if(n[1] === 0x4B && n[2] < 0x20 && n[3] < 0x20) return read_zip(d, o); break; + case 0x50: return (n[1] === 0x4B && n[2] < 0x09 && n[3] < 0x09) ? read_zip(d, o) : read_prn(data, d, o, str); break; ```
superlbr commented 2018-04-27 01:57:24 +00:00 (Migrated from github.com)

Well, repeated again with npm package xlsx (version 0.12.10)

nodejs.Error: Corrupted zip : can't find end of central directory
    at ZipEntries.readEndOfCentral (/opt/tuhuo/api/node_modules/xlsx/jszip.js:2273:19)
    at ZipEntries.load (/opt/tuhuo/api/node_modules/xlsx/jszip.js:2335:14)
    at new ZipEntries (/opt/tuhuo/api/node_modules/xlsx/jszip.js:2159:14)
    at JSZipSync.module.exports [as load] (/opt/tuhuo/api/node_modules/xlsx/jszip.js:580:18)
    at new JSZipSync (/opt/tuhuo/api/node_modules/xlsx/jszip.js:527:14)
    at read_zip (/opt/tuhuo/api/node_modules/xlsx/xlsx.js:19192:24)
    at readSync (/opt/tuhuo/api/node_modules/xlsx/xlsx.js:19260:69)
    at Object.readFileSync (/opt/tuhuo/api/node_modules/xlsx/xlsx.js:19274:9)
    at Object.parse (/opt/tuhuo/api/node_modules/node-xlsx/src/index.js:7:21)
Well, repeated again with npm package xlsx (version 0.12.10) ``` nodejs.Error: Corrupted zip : can't find end of central directory at ZipEntries.readEndOfCentral (/opt/tuhuo/api/node_modules/xlsx/jszip.js:2273:19) at ZipEntries.load (/opt/tuhuo/api/node_modules/xlsx/jszip.js:2335:14) at new ZipEntries (/opt/tuhuo/api/node_modules/xlsx/jszip.js:2159:14) at JSZipSync.module.exports [as load] (/opt/tuhuo/api/node_modules/xlsx/jszip.js:580:18) at new JSZipSync (/opt/tuhuo/api/node_modules/xlsx/jszip.js:527:14) at read_zip (/opt/tuhuo/api/node_modules/xlsx/xlsx.js:19192:24) at readSync (/opt/tuhuo/api/node_modules/xlsx/xlsx.js:19260:69) at Object.readFileSync (/opt/tuhuo/api/node_modules/xlsx/xlsx.js:19274:9) at Object.parse (/opt/tuhuo/api/node_modules/node-xlsx/src/index.js:7:21) ```
reviewher commented 2018-04-27 02:28:03 +00:00 (Migrated from github.com)

@superlbr can you upload a file ?

@superlbr can you upload a file ?
reviewher commented 2018-04-27 03:20:27 +00:00 (Migrated from github.com)

Can't reproduce the issue against 0.12.10:

$ xlsx --version
0.12.10
$ xlsx ~/Downloads/0427.xlsx | sed 's/,*$//'
sheet1
,,,,,,,团购导入表
团购名称,用户名称,收货地址,收货人电话,送达日期,备注,订单属性,,,产品列表
--------请从下一行开始填写--------,,,,,,,托曼尼榴莲,佳沛金果(原箱),佳沛金果(盒),香蕉,南汇玉菇甜瓜
城市经典高迪,a,,,4/27/18,,1
城市经典高迪,b,,,4/27/18,,1
城市经典高迪,v,,,4/27/18,,1
城市经典高迪,c,,,4/27/18,,1,,,,1
城市经典高迪,d,,,4/27/18,,1
Can't reproduce the issue against 0.12.10: ``` $ xlsx --version 0.12.10 $ xlsx ~/Downloads/0427.xlsx | sed 's/,*$//' sheet1 ,,,,,,,团购导入表 团购名称,用户名称,收货地址,收货人电话,送达日期,备注,订单属性,,,产品列表 --------请从下一行开始填写--------,,,,,,,托曼尼榴莲,佳沛金果(原箱),佳沛金果(盒),香蕉,南汇玉菇甜瓜 城市经典高迪,a,,,4/27/18,,1 城市经典高迪,b,,,4/27/18,,1 城市经典高迪,v,,,4/27/18,,1 城市经典高迪,c,,,4/27/18,,1,,,,1 城市经典高迪,d,,,4/27/18,,1 ```
superlbr commented 2018-04-27 06:17:22 +00:00 (Migrated from github.com)

yeah, the file is ok.
But little change in saving from request's file stream.
Look out when fs.createWriteStream deal with xlsx file
Other people see this, please read https://github.com/SheetJS/js-xlsx#streaming-read

yeah, the file is ok. But little change in saving from request's file stream. Look out when fs.createWriteStream deal with xlsx file Other people see this, please read https://github.com/SheetJS/js-xlsx#streaming-read
rushglen commented 2019-11-04 19:10:16 +00:00 (Migrated from github.com)

Got this error using SZip v3.2.1 when using jszip.min.js

Can't find end of central directory : is this a zip file ? If it is, see

https://stuk.github.io/jszip/documentation/howto/read_zip.html

If I use jszip.js (not minified version) it works!

Got this error using SZip v3.2.1 when using **jszip.min.js** > Can't find end of central directory : is this a zip file ? If it is, see > > https://stuk.github.io/jszip/documentation/howto/read_zip.html If I use **jszip.js** (not minified version) it works!
idubi commented 2021-11-08 08:46:24 +00:00 (Migrated from github.com)

workbook.xlsx.readFile ..... will try to load xlsx file

that is a compressed excel file
so it will fail with this message :

_stack:'Error: Can't find end of central directory_

only try to use it on compressed excel file

if you want to load a csv file you need to use : _workbook.csv.readFile_
if you want a regular excel (uncompressed) then : _workbook.excel.readFile_

`workbook.xlsx.readFile` ..... will try to load xlsx file that is a compressed excel file so it will fail with this message : `_stack:'Error: Can't find end of central directory_ ` only try to use it on compressed excel file if you want to load a csv file you need to use :` _workbook.csv.readFile_` if you want a regular excel (uncompressed) then : `_workbook.excel.readFile_`
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#1013
No description provided.