Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
62d9a7f
src: fix unchecked return warning from coverity
mhdawson Mar 1, 2022
19851f8
doc: readline `'line'` event emits final line
mattpr Mar 7, 2022
a4632a3
crypto: add CHECKs to remaining BIO_s_mem allocs
tniessen Mar 7, 2022
e95426f
tools: fix web streams API links
mscdex Mar 7, 2022
7fc4b9f
meta: add dependencies label to label-pr-config
Mesteery Mar 7, 2022
1d0468f
crypto: fix fingerprint string size calculation
tniessen Mar 7, 2022
f27bcec
build: use ccache in make-v8.sh on ppc64le and s390x
richardlau Mar 7, 2022
b89f4d5
url: trim leading and trailing C0 control chars
Trott Mar 8, 2022
3492a0e
string_decoder: fix crash when calling __proto__.write()
RaisinTen Mar 8, 2022
f3c6c00
doc: remove refs to old OpenSSL list-* commands
tniessen Mar 8, 2022
70c0758
deps: upgrade npm to 8.5.3
npm-robot Mar 3, 2022
69a3792
lib: fix AsyncResource.bind not using 'this' from the caller by default
rochdev Mar 8, 2022
2335467
doc: deprecate string coercion in `fs.write`, `fs.writeFileSync`
LiviaMedeiros Mar 8, 2022
9af9083
src: use `emplace_back` instead of `push_back`
yashLadha Mar 8, 2022
a4aa9eb
test: use global webcrypto for WPT tests
aduh95 Mar 8, 2022
58763d7
src,crypto: avoid tristate Maybe<bool> in ExportJWKEcKey()
RaisinTen Mar 8, 2022
3b55946
debugger: correct typo in inspect_repl.js
cola119 Mar 9, 2022
b60262e
deps: update undici to 4.15.1
targos Mar 7, 2022
1796f03
build: rename tools workflow and add undici to it
targos Mar 7, 2022
701dc14
doc: remove outdated timeout.unref content
meixg Mar 10, 2022
88dee3c
http2: fix potential integer overflow
mhdawson Mar 10, 2022
4829a10
esm: add runtime warning for specifier resolution flag
GeoffreyBooth Mar 10, 2022
d06e92d
src: perform minor cleanups on zlib code
addaleax Mar 10, 2022
063ff08
deps: V8: cherry-pick c6f6626deb14
luyahan Mar 10, 2022
e43aa30
src: remove redundant buffer size check
tniessen Mar 10, 2022
94e5eaa
test: add test case for reverted 17.7 regression
Trott Mar 11, 2022
fe01940
url: preserve null char in WHATWG URL errors
Trott Mar 11, 2022
9fc4b9b
src: include internal/options in the snapshot
joyeecheung Mar 3, 2022
e7b8d83
meta: update AUTHORS
nodejs-github-bot Mar 13, 2022
f2178fc
deps: cares: cherry-pick b5a3d96
bradh352 Mar 2, 2022
8b99099
doc: improve pipe description
mifi Mar 13, 2022
72dd500
doc: clarify the meaning of legacy status
RaisinTen Mar 14, 2022
eb0e1a1
tools: update eslint to 8.11.0
nodejs-github-bot Mar 14, 2022
08e2d8a
src: check return value of HMAC_Final
tniessen Mar 14, 2022
e17db8f
esm: improve typings and code coverage
bmeck Mar 11, 2022
9500e58
src: avoid returning invalid value from hex2bin
tniessen Mar 14, 2022
8b84e68
src: simplify bound check in ParseArrayIndex
tniessen Mar 14, 2022
30ea188
tools: update lint-md-dependencies to rollup@2.70.0 unified@10.1.2
nodejs-github-bot Mar 14, 2022
b7a4b4b
tools: update doc to highlight.js@11.5.0 unified@10.1.2
nodejs-github-bot Mar 14, 2022
846b074
src: check EC_POINT_get_affine_coordinates result
tniessen Mar 14, 2022
21198c1
src: fix coverity warnings in node_file.cc
mhdawson Mar 9, 2022
4941791
test: improve _http_outgoing coverage
kuriyosh Mar 14, 2022
dfdce7c
test: improve _http_incoming.js coverage
kuriyosh Mar 14, 2022
96dc591
doc: clarify path search in `child_process.spawn`
zobo Mar 14, 2022
fd7e4ab
doc: fix async iterable pipeline signal examples
tilgovi Mar 14, 2022
1fe0b69
lib: refactor to use primordials in `lib/assert.js`
marsonya Mar 15, 2022
e55283b
esm: make extension-less errors in type:module actionable
bmeck Mar 15, 2022
e7e8eb9
doc: update base branch name for `nodejs/nodejs.org`
danielleadams Mar 16, 2022
3bd0078
doc: add @ShogunPanda to collaborators
ShogunPanda Mar 16, 2022
5367002
stream: do cleanup when iterator is destroyed
KhooHaoYit Mar 16, 2022
46d3d23
doc: revise async_hooks docs
Trott Mar 17, 2022
6c265e7
doc: remove unneeded lint disable comment
Trott Mar 17, 2022
a5e42f0
doc: fix Embedder's Guide link to V8 official docs
aroyan Mar 17, 2022
b82bac0
test: improve https_renew_cert.sh script
tniessen Mar 17, 2022
229fb40
worker: do not send message if port is closing
Trott Mar 16, 2022
da42ffb
http: trace http client by perf_hooks
theanarkh Mar 18, 2022
78b858d
doc: document goal to have examples
mhdawson Mar 9, 2022
e960424
src: convert hex2bin() into a regular function
RaisinTen Mar 18, 2022
d9a5c2b
test: give slow tests more time on Rasberry PIs
mhdawson Mar 17, 2022
04a7c00
doc: update instructions for openssl updates
mhdawson Mar 15, 2022
88d3401
doc: add that chacha20-poly1305 is IETF version
tniessen Mar 19, 2022
84fd6e5
deps: upgrade npm to 8.5.5
npm-robot Mar 17, 2022
26d4a2d
test,crypto: add and update empty passphrase regression tests
RaisinTen Mar 19, 2022
db83c4d
doc: improve README.md usability
Trott Mar 19, 2022
f48c3ba
crypto: fix auth tag length error when mode != GCM
tniessen Mar 20, 2022
38e7681
tools: update lint-md-dependencies to rollup@2.70.1
nodejs-github-bot Mar 20, 2022
1c87ce6
meta: update AUTHORS
nodejs-github-bot Mar 20, 2022
4fd2aff
tools: make update-undici script executable
targos Mar 20, 2022
fd51e78
doc: fix version history for `net.Socket` and `net.Server`
aduh95 Mar 9, 2022
123661e
2022-03-22, Version 17.8.0 (Current)
bengl Mar 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src: perform minor cleanups on zlib code
- Use `final` to indicate the classes that we actually
  instantiate
- Properly use `const` (and the necessary associated `const_cast`
  for zlib because we don’t define `ZLIB_CONST` and allow shared
  builds)
- Store the JS callback in an internal field rather than a `Global`
  (which improves memory leak debugging capabilities, removes
  a potential future memory leak footgun, and aligns the code
  with the rest of the codebase more closely)
- Other minor C++ cleanup

PR-URL: #42247
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and bengl committed Mar 20, 2022
commit d06e92dba0849f459d1362ed361710f4a0885f6c
49 changes: 27 additions & 22 deletions src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ using v8::Context;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Global;
using v8::HandleScope;
using v8::Int32;
using v8::Integer;
Expand Down Expand Up @@ -107,8 +106,8 @@ enum node_zlib_mode {
BROTLI_ENCODE
};

#define GZIP_HEADER_ID1 0x1f
#define GZIP_HEADER_ID2 0x8b
constexpr uint8_t GZIP_HEADER_ID1 = 0x1f;
constexpr uint8_t GZIP_HEADER_ID2 = 0x8b;

struct CompressionError {
CompressionError(const char* message, const char* code, int err)
Expand All @@ -127,14 +126,14 @@ struct CompressionError {
inline bool IsError() const { return code != nullptr; }
};

class ZlibContext : public MemoryRetainer {
class ZlibContext final : public MemoryRetainer {
public:
ZlibContext() = default;

// Streaming-related, should be available for all compression libraries:
void Close();
void DoThreadPoolWork();
void SetBuffers(char* in, uint32_t in_len, char* out, uint32_t out_len);
void SetBuffers(const char* in, uint32_t in_len, char* out, uint32_t out_len);
void SetFlush(int flush);
void GetAfterWriteOffsets(uint32_t* avail_in, uint32_t* avail_out) const;
CompressionError GetErrorInfo() const;
Expand Down Expand Up @@ -183,7 +182,7 @@ class BrotliContext : public MemoryRetainer {
public:
BrotliContext() = default;

void SetBuffers(char* in, uint32_t in_len, char* out, uint32_t out_len);
void SetBuffers(const char* in, uint32_t in_len, char* out, uint32_t out_len);
void SetFlush(int flush);
void GetAfterWriteOffsets(uint32_t* avail_in, uint32_t* avail_out) const;
inline void SetMode(node_zlib_mode mode) { mode_ = mode; }
Expand All @@ -193,7 +192,7 @@ class BrotliContext : public MemoryRetainer {

protected:
node_zlib_mode mode_ = NONE;
uint8_t* next_in_ = nullptr;
const uint8_t* next_in_ = nullptr;
uint8_t* next_out_ = nullptr;
size_t avail_in_ = 0;
size_t avail_out_ = 0;
Expand Down Expand Up @@ -251,6 +250,12 @@ class BrotliDecoderContext final : public BrotliContext {
template <typename CompressionContext>
class CompressionStream : public AsyncWrap, public ThreadPoolWork {
public:
enum InternalFields {
kCompressionStreamBaseField = AsyncWrap::kInternalFieldCount,
kWriteJSCallback,
kInternalFieldCount
};

CompressionStream(Environment* env, Local<Object> wrap)
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_ZLIB),
ThreadPoolWork(env),
Expand All @@ -259,7 +264,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
}

~CompressionStream() override {
CHECK_EQ(false, write_in_progress_ && "write in progress");
CHECK(!write_in_progress_);
Close();
CHECK_EQ(zlib_memory_, 0);
CHECK_EQ(unreported_allocations_, 0);
Expand Down Expand Up @@ -295,7 +300,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
CHECK_EQ(args.Length(), 7);

uint32_t in_off, in_len, out_off, out_len, flush;
char* in;
const char* in;
char* out;

CHECK_EQ(false, args[0]->IsUndefined() && "must provide flush value");
Expand Down Expand Up @@ -340,7 +345,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {

template <bool async>
void Write(uint32_t flush,
char* in, uint32_t in_len,
const char* in, uint32_t in_len,
char* out, uint32_t out_len) {
AllocScope alloc_scope(this);

Expand Down Expand Up @@ -394,6 +399,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {

// v8 land!
void AfterThreadPoolWork(int status) override {
DCHECK(init_done_);
AllocScope alloc_scope(this);
auto on_scope_leave = OnScopeLeave([&]() { Unref(); });

Expand All @@ -416,9 +422,8 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
UpdateWriteResult();

// call the write() cb
Local<Function> cb = PersistentToLocal::Default(env->isolate(),
write_js_callback_);
MakeCallback(cb, 0, nullptr);
Local<Value> cb = object()->GetInternalField(kWriteJSCallback);
MakeCallback(cb.As<Function>(), 0, nullptr);

if (pending_close_)
Close();
Expand All @@ -431,7 +436,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());

HandleScope scope(env->isolate());
Local<Value> args[3] = {
Local<Value> args[] = {
OneByteString(env->isolate(), err.message),
Integer::New(env->isolate(), err.err),
OneByteString(env->isolate(), err.code)
Expand Down Expand Up @@ -465,7 +470,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {

void InitStream(uint32_t* write_result, Local<Function> write_js_callback) {
write_result_ = write_result;
write_js_callback_.Reset(AsyncWrap::env()->isolate(), write_js_callback);
object()->SetInternalField(kWriteJSCallback, write_js_callback);
init_done_ = true;
}

Expand Down Expand Up @@ -540,14 +545,13 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
bool closed_ = false;
unsigned int refs_ = 0;
uint32_t* write_result_ = nullptr;
Global<Function> write_js_callback_;
std::atomic<ssize_t> unreported_allocations_{0};
size_t zlib_memory_ = 0;

CompressionContext ctx_;
};

class ZlibStream : public CompressionStream<ZlibContext> {
class ZlibStream final : public CompressionStream<ZlibContext> {
public:
ZlibStream(Environment* env, Local<Object> wrap, node_zlib_mode mode)
: CompressionStream(env, wrap) {
Expand Down Expand Up @@ -646,7 +650,8 @@ class ZlibStream : public CompressionStream<ZlibContext> {
};

template <typename CompressionContext>
class BrotliCompressionStream : public CompressionStream<CompressionContext> {
class BrotliCompressionStream final :
public CompressionStream<CompressionContext> {
public:
BrotliCompressionStream(Environment* env,
Local<Object> wrap,
Expand Down Expand Up @@ -857,10 +862,10 @@ void ZlibContext::DoThreadPoolWork() {
}


void ZlibContext::SetBuffers(char* in, uint32_t in_len,
void ZlibContext::SetBuffers(const char* in, uint32_t in_len,
char* out, uint32_t out_len) {
strm_.avail_in = in_len;
strm_.next_in = reinterpret_cast<Bytef*>(in);
strm_.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(in));
strm_.avail_out = out_len;
strm_.next_out = reinterpret_cast<Bytef*>(out);
}
Expand Down Expand Up @@ -1093,9 +1098,9 @@ CompressionError ZlibContext::SetParams(int level, int strategy) {
}


void BrotliContext::SetBuffers(char* in, uint32_t in_len,
void BrotliContext::SetBuffers(const char* in, uint32_t in_len,
char* out, uint32_t out_len) {
next_in_ = reinterpret_cast<uint8_t*>(in);
next_in_ = reinterpret_cast<const uint8_t*>(in);
next_out_ = reinterpret_cast<uint8_t*>(out);
avail_in_ = in_len;
avail_out_ = out_len;
Expand Down