File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const Module = require ( 'module' ) ;
22const fs = require ( 'fs' ) ;
33const path = require ( 'path' ) ;
4- const os = require ( 'os' ) ;
54
65const originalResolveFilename = Module . _resolveFilename ;
76
87Module . _resolveFilename = function ( request , parent , isMain , options ) {
98 if ( request === 'yargs/yargs' ) {
109 const resolved = originalResolveFilename . apply ( this , arguments ) ;
11- // Create a unique shim file in tmpdir based on the exact path to avoid collisions
10+ if ( resolved . endsWith ( '.mjs' ) ) {
11+ return resolved ;
12+ }
13+ // Create a unique shim file in the local scripts directory to avoid shared temp directory vulnerabilities
1214 const safeHash = Buffer . from ( resolved ) . toString ( 'base64' ) . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '' ) ;
13- const shimPath = path . join ( os . tmpdir ( ) , `yargs-shim-${ safeHash } .cjs` ) ;
15+ const shimPath = path . join ( __dirname , `yargs-shim-${ safeHash } .cjs` ) ;
1416
1517 if ( ! fs . existsSync ( shimPath ) ) {
1618 const content = fs . readFileSync ( resolved , 'utf8' ) ;
Original file line number Diff line number Diff line change @@ -2188,13 +2188,25 @@ class File extends ServiceObject<File, FileMetadata> {
21882188 emitStream . removeListener ( 'error' , noop ) ;
21892189
21902190 if ( fileWriteStream . destroyed ) {
2191- fileWriteStream . once ( 'error' , ( err : Error ) => {
2192- pipelineCallback ( err ) ;
2193- } ) ;
2194- // Call pipelineCallback immediately if there's no error to wait for,
2195- // though duplexify might emit error on next tick.
2196- // Also cleanup emitStream since pipeline won't do it.
2191+ let callbackCalled = false ;
2192+ const onError = ( err : Error ) => {
2193+ if ( ! callbackCalled ) {
2194+ callbackCalled = true ;
2195+ pipelineCallback ( err ) ;
2196+ }
2197+ } ;
2198+ fileWriteStream . once ( 'error' , onError ) ;
21972199 emitStream . destroy ( ) ;
2200+
2201+ process . nextTick ( ( ) => {
2202+ fileWriteStream . removeListener ( 'error' , onError ) ;
2203+ if ( ! callbackCalled ) {
2204+ callbackCalled = true ;
2205+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2206+ const err = ( fileWriteStream as any ) . errored || new Error ( 'Write stream destroyed' ) ;
2207+ pipelineCallback ( err ) ;
2208+ }
2209+ } ) ;
21982210 return ;
21992211 }
22002212
You can’t perform that action at this time.
0 commit comments