Skip to content

Commit a5db8a3

Browse files
trop[bot]frank-pianjkleinsc
authored
fix: session.getBlobData never resolves with blob sizes > 65536 (#35602)
fix: session.getBlobData never resolves with blob sizes > 65536 (#35277) * fix: session.getBlobData never resolves with blob sizes > 65536 (#34398) * Add unit test case for session.getBlobData Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Frank Pian <bianyongfang@vip.qq.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
1 parent 85f93bc commit a5db8a3

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

shell/browser/api/electron_api_data_pipe_holder.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ class DataPipeReader {
8686
if (result == MOJO_RESULT_OK) { // success
8787
remaining_size_ -= length;
8888
head_ += length;
89-
if (remaining_size_ == 0)
89+
if (remaining_size_ == 0) {
9090
OnSuccess();
91+
} else {
92+
handle_watcher_.ArmOrNotify();
93+
}
9194
} else if (result == MOJO_RESULT_SHOULD_WAIT) { // IO pending
9295
handle_watcher_.ArmOrNotify();
9396
} else { // error

spec-main/api-session-spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,50 @@ describe('session module', () => {
529529
});
530530
});
531531

532+
describe('ses.getBlobData2()', () => {
533+
const scheme = 'cors-blob';
534+
const protocol = session.defaultSession.protocol;
535+
const url = `${scheme}://host`;
536+
after(async () => {
537+
await protocol.unregisterProtocol(scheme);
538+
});
539+
afterEach(closeAllWindows);
540+
541+
it('returns blob data for uuid', (done) => {
542+
const content = `<html>
543+
<script>
544+
let fd = new FormData();
545+
fd.append("data", new Blob(new Array(65_537).fill('a')));
546+
fetch('${url}', {method:'POST', body: fd });
547+
</script>
548+
</html>`;
549+
550+
protocol.registerStringProtocol(scheme, (request, callback) => {
551+
try {
552+
if (request.method === 'GET') {
553+
callback({ data: content, mimeType: 'text/html' });
554+
} else if (request.method === 'POST') {
555+
const uuid = request.uploadData![1].blobUUID;
556+
expect(uuid).to.be.a('string');
557+
session.defaultSession.getBlobData(uuid!).then(result => {
558+
try {
559+
const data = new Array(65_537).fill('a');
560+
expect(result.toString()).to.equal(data.join(''));
561+
done();
562+
} catch (e) {
563+
done(e);
564+
}
565+
});
566+
}
567+
} catch (e) {
568+
done(e);
569+
}
570+
});
571+
const w = new BrowserWindow({ show: false });
572+
w.loadURL(url);
573+
});
574+
});
575+
532576
describe('ses.setCertificateVerifyProc(callback)', () => {
533577
let server: http.Server;
534578

0 commit comments

Comments
 (0)