Truncate stream names to 31 characters

fixes https://github.com/SheetJS/js-cfb/issues/18
This commit is contained in:
John Shearer 2022-11-10 10:35:49 +00:00
parent 5a5870eb1b
commit b01260294e
2 changed files with 6 additions and 6 deletions

View File

@ -9,9 +9,9 @@
file = cfb.FileIndex[i];
if(i === 0) file.start = file.size ? file.start - 1 : ENDOFCHAIN;
var _nm/*:string*/ = (i === 0 && _opts.root) || file.name;
if(_nm.length > 32) {
console.error("Name " + _nm + " will be truncated to " + _nm.slice(0,32));
_nm = _nm.slice(0, 32);
if(_nm.length > 31) {
console.error("Name " + _nm + " will be truncated to " + _nm.slice(0,31));
_nm = _nm.slice(0, 31);
}
flen = 2*(_nm.length+1);
o.write_shift(64, _nm, "utf16le");

6
cfb.js
View File

@ -891,9 +891,9 @@ flen = file.content.length;
file = cfb.FileIndex[i];
if(i === 0) file.start = file.size ? file.start - 1 : ENDOFCHAIN;
var _nm = (i === 0 && _opts.root) || file.name;
if(_nm.length > 32) {
console.error("Name " + _nm + " will be truncated to " + _nm.slice(0,32));
_nm = _nm.slice(0, 32);
if(_nm.length > 31) {
console.error("Name " + _nm + " will be truncated to " + _nm.slice(0,31));
_nm = _nm.slice(0, 31);
}
flen = 2*(_nm.length+1);
o.write_shift(64, _nm, "utf16le");