Skip to content

Commit

Permalink
Handle zero-sized files (#4530)
Browse files Browse the repository at this point in the history
* Handle zero-sized files

It appears that having a zero-sized file won't call our `next()` handler which means we wedge forever and eventually time out.

This is a workaround. Upstream issue filed as mafintosh/tar-stream#145
  • Loading branch information
mattgodbolt committed Jan 24, 2023
1 parent 1882ec3 commit 908890b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/buildenvsetup/ceconan.ts
Expand Up @@ -128,6 +128,7 @@ export class BuildEnvSetupCeConanDirect extends BuildEnvSetupBase {
const resolved = path.resolve(path.dirname(filepath));
if (!resolved.startsWith(downloadPath)) {
logger.error(`Library ${libId}/${version} is using a zip-slip, skipping file`);
stream.resume();
next();
return;
}
Expand All @@ -136,13 +137,20 @@ export class BuildEnvSetupCeConanDirect extends BuildEnvSetupBase {
}

const filestream = fs.createWriteStream(filepath);
stream.pipe(filestream);
stream.on('error', error => {
logger.error(`Error in stream handling: ${error}`);
reject(error);
});
stream.on('end', next);
stream.resume();
if (header.size === 0) {
// See https://github.com/mafintosh/tar-stream/issues/145
stream.resume();
next();
} else {
stream
.on('error', error => {
logger.error(`Error in stream handling: ${error}`);
reject(error);
})
.on('end', next)
.pipe(filestream);
stream.resume();
}
} catch (error) {
logger.error(`Error in entry handling: ${error}`);
reject(error);
Expand Down Expand Up @@ -254,10 +262,10 @@ export class BuildEnvSetupCeConanDirect extends BuildEnvSetupBase {
}),
);
} else {
logger.info(`No build found for ${libVer} matching ${JSON.stringify(buildProperties)}`);
logger.warn(`No build found for ${libVer} matching ${JSON.stringify(buildProperties)}`);
}
} else {
logger.info(`Library ${libVer} not available`);
logger.warn(`Library ${libVer} not available`);
}
}

Expand Down

0 comments on commit 908890b

Please sign in to comment.