Description: Remove paths from dirCache when no longer dirs Author: isaacs <i@izs.me> Origin: upstream, https://github.com/npm/node-tar/commit/9dbdeb6 Bug: https://github.com/npm/node-tar/security/advisories/GHSA-r628-mhmh-qjhw Bug-Debian: https://bugs.debian.org/992110 Forwarded: not-needed Reviewed-By: Yadd <yadd@debian.org> Last-Update: 2021-08-11 --- a/lib/unpack.js +++ b/lib/unpack.js @@ -461,6 +461,19 @@ this.reservations.reserve(paths, done => this[CHECKFS2](entry, done)) } [CHECKFS2] (entry, done) { + // if we are not creating a directory, and the path is in the dirCache, + // then that means we are about to delete the directory we created + // previously, and it is no longer going to be a directory, and neither + // is any of its children. + if (entry.type !== 'Directory') { + for (const path of this.dirCache.keys()) { + if (path === entry.absolute || + path.indexOf(entry.absolute + '/') === 0 || + path.indexOf(entry.absolute + '\\') === 0) + this.dirCache.delete(path) + } + } + this[MKDIR](path.dirname(entry.absolute), this.dmode, er => { if (er) { done() @@ -528,6 +541,15 @@ } [CHECKFS] (entry) { + if (entry.type !== 'Directory') { + for (const path of this.dirCache.keys()) { + if (path === entry.absolute || + path.indexOf(entry.absolute + '/') === 0 || + path.indexOf(entry.absolute + '\\') === 0) + this.dirCache.delete(path) + } + } + const er = this[MKDIR](path.dirname(entry.absolute), this.dmode, neverCalled) if (er) return this[ONERROR](er, entry)