Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't find end of central directory #1013

Closed
wlpeter opened this issue Mar 2, 2018 · 7 comments
Closed

can't find end of central directory #1013

wlpeter opened this issue Mar 2, 2018 · 7 comments

Comments

@wlpeter
Copy link

wlpeter commented Mar 2, 2018

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)

@wlpeter wlpeter closed this as completed Mar 2, 2018
@SheetJSDev
Copy link
Contributor

@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;

@SheetJSDev SheetJSDev reopened this Mar 2, 2018
@wlpeter wlpeter closed this as completed Mar 2, 2018
SheetJSDev added a commit that referenced this issue Mar 6, 2018
- PK magic number bound (fixes #1013 h/t @wlpeter)
- removed JSZip conflict (fixes #1017 h/t @seanmars)
- updated CFB to 1.0.5
- demo HTML conversion `string`
@superlbr
Copy link

superlbr commented Apr 27, 2018

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
Copy link
Contributor

@superlbr can you upload a file ?

@reviewher
Copy link
Contributor

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
Copy link

superlbr commented Apr 27, 2018

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
Copy link

rushglen commented Nov 4, 2019

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!

RimaCiklum pushed a commit to Folcon/js-xlsx that referenced this issue Aug 20, 2020
- PK magic number bound (fixes SheetJS#1013 h/t @wlpeter)
- removed JSZip conflict (fixes SheetJS#1017 h/t @seanmars)
- updated CFB to 1.0.5
- demo HTML conversion `string`
@idubi
Copy link

idubi commented Nov 8, 2021

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants