@@ -120,6 +120,8 @@ exports.extract = function extract (cwd, opts) {
120
120
if ( ! cwd ) cwd = '.'
121
121
if ( ! opts ) opts = { }
122
122
123
+ cwd = path . resolve ( cwd )
124
+
123
125
const xfs = opts . fs || fs
124
126
const ignore = opts . ignore || opts . filter || noop
125
127
const mapStream = opts . mapStream || echo
@@ -216,18 +218,21 @@ exports.extract = function extract (cwd, opts) {
216
218
function onsymlink ( ) {
217
219
if ( win32 ) return next ( ) // skip symlinks on win for now before it can be tested
218
220
xfs . unlink ( name , function ( ) {
221
+ const dst = path . resolve ( path . dirname ( name ) , header . linkname )
222
+ if ( ! inCwd ( dst ) ) return next ( new Error ( name + ' is not a valid symlink' ) )
223
+
219
224
xfs . symlink ( header . linkname , name , stat )
220
225
} )
221
226
}
222
227
223
228
function onlink ( ) {
224
229
if ( win32 ) return next ( ) // skip links on win for now before it can be tested
225
230
xfs . unlink ( name , function ( ) {
226
- const srcpath = path . join ( cwd , path . join ( '/' , header . linkname ) )
231
+ const dst = path . join ( cwd , path . join ( '/' , header . linkname ) )
227
232
228
- xfs . link ( srcpath , name , function ( err ) {
233
+ xfs . link ( dst , name , function ( err ) {
229
234
if ( err && err . code === 'EPERM' && opts . hardlinkAsFilesFallback ) {
230
- stream = xfs . createReadStream ( srcpath )
235
+ stream = xfs . createReadStream ( dst )
231
236
return onfile ( )
232
237
}
233
238
@@ -236,6 +241,10 @@ exports.extract = function extract (cwd, opts) {
236
241
} )
237
242
}
238
243
244
+ function inCwd ( dst ) {
245
+ return dst . startsWith ( cwd )
246
+ }
247
+
239
248
function onfile ( ) {
240
249
const ws = xfs . createWriteStream ( name )
241
250
const rs = mapStream ( stream , header )
0 commit comments