diff --git a/packages/playwright/src/reporters/blob.ts b/packages/playwright/src/reporters/blob.ts index a1411271a62c7..660a101b69639 100644 --- a/packages/playwright/src/reporters/blob.ts +++ b/packages/playwright/src/reporters/blob.ts @@ -84,9 +84,13 @@ export class BlobReporter extends TeleReporterEmitter { zipFinishPromise.resolve(undefined); }).on('error', error => zipFinishPromise.reject(error)); + const addedEntries = new Set(); for (const { originalPath, zipEntryPath } of this._attachments) { + if (addedEntries.has(zipEntryPath)) + continue; if (!fs.statSync(originalPath, { throwIfNoEntry: false })?.isFile()) continue; + addedEntries.add(zipEntryPath); zipFile.addFile(originalPath, zipEntryPath); } diff --git a/packages/utils/third_party/extractZip.ts b/packages/utils/third_party/extractZip.ts index 1dc0d27253042..3508e2f6bcc27 100644 --- a/packages/utils/third_party/extractZip.ts +++ b/packages/utils/third_party/extractZip.ts @@ -177,7 +177,10 @@ class Extractor { debug('creating symlink', link, dest); await fs.symlink(link, dest); } else { - await pipeline(readStream, createWriteStream(dest, { mode: procMode })); + // 'wx' fails when dest exists, including a symlink left by a previous entry. + // Otherwise an archive could place a symlink and then a regular file with the + // same name to write outside of the extraction directory. + await pipeline(readStream, createWriteStream(dest, { mode: procMode, flags: 'wx' })); } }