Skip to content

Commit

Permalink
fix: setfiles OOM exception (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
railwayursin authored Sep 18, 2023
1 parent 25ba847 commit 30778a3
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ static String mimeType(Path path) {
return mimeType;
}

static final int maxUplodBufferSize = 50 * 1024 * 1024;
static final long maxUploadBufferSize = 50 * 1024 * 1024;

static boolean hasLargeFile(Path[] files) {
int totalSize = 0;
long totalSize = 0;
for (Path file: files) {
try {
totalSize += Files.size(file);
} catch (IOException e) {
throw new PlaywrightException("Cannot get file size.", e);
}
}
return totalSize > maxUplodBufferSize;
return totalSize > maxUploadBufferSize;
}

static void addLargeFileUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
Expand Down Expand Up @@ -216,11 +216,11 @@ static void addLargeFileUploadParams(Path[] files, JsonObject params, BrowserCon
}

static void checkFilePayloadSize(FilePayload[] files) {
int totalSize = 0;
long totalSize = 0;
for (FilePayload file: files) {
totalSize += file.buffer.length;
}
if (totalSize > maxUplodBufferSize) {
if (totalSize > maxUploadBufferSize) {
throw new PlaywrightException("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.");
}
}
Expand Down

0 comments on commit 30778a3

Please sign in to comment.