| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1cdd23c commit e992a34
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -644,6 +644,12 @@ class CompressionStream : public AsyncWrap, | |||
| 644 | 644 | CompressionStream* wrap; | |
| 645 | 645 | ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This()); | |
| 646 | 646 | ||
| 647 | + if (wrap->write_in_progress_) { | ||
| 648 | + wrap->env()->ThrowError( | ||
| 649 | + "Cannot reset zlib stream while a write is in progress"); | ||
| 650 | + return; | ||
| 651 | + } | ||
| 652 | + | ||
| 647 | 653 | AllocScope alloc_scope(wrap); | |
| 648 | 654 | const CompressionError err = wrap->context()->ResetStream(); | |
| 649 | 655 | if (err.IsError()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const { createBrotliCompress, createDeflate } = require('zlib'); | ||
| 5 | + | ||
| 6 | + // Tests that calling .reset() while an async write is in progress | ||
| 7 | + // throws an error instead of causing a use-after-free. | ||
| 8 | + | ||
| 9 | + for (const factory of [createBrotliCompress, createDeflate]) { | ||
| 10 | + const stream = factory(); | ||
| 11 | + const input = Buffer.alloc(1024, 0x41); | ||
| 12 | + | ||
| 13 | + stream.write(input, common.mustCall()); | ||
| 14 | + stream.on('error', common.mustNotCall()); | ||
| 15 | + | ||
| 16 | + // The write has been dispatched to the thread pool. | ||
| 17 | + // Calling reset while write is in progress must throw. | ||
| 18 | + assert.throws(() => { | ||
| 19 | + stream._handle.reset(); | ||
| 20 | + }, { | ||
| 21 | + message: 'Cannot reset zlib stream while a write is in progress', | ||
| 22 | + }); | ||
| 23 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments