| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 433bd1b commit ec15504
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -820,10 +820,15 @@ CipherBase::UpdateResult CipherBase::Update( | |||
| 820 | 820 | len); | |
| 821 | 821 | ||
| 822 | 822 | CHECK_LE(static_cast<size_t>(buf_len), (*out)->ByteLength()); | |
| 823 | - if (buf_len == 0) | ||
| 823 | + if (buf_len == 0) { | ||
| 824 | 824 | *out = ArrayBuffer::NewBackingStore(env()->isolate(), 0); | |
| 825 | - else | ||
| 826 | - *out = BackingStore::Reallocate(env()->isolate(), std::move(*out), buf_len); | ||
| 825 | + } else if (static_cast<size_t>(buf_len) != (*out)->ByteLength()) { | ||
| 826 | + std::unique_ptr<BackingStore> old_out = std::move(*out); | ||
| 827 | + *out = ArrayBuffer::NewBackingStore(env()->isolate(), buf_len); | ||
| 828 | + memcpy(static_cast<char*>((*out)->Data()), | ||
| 829 | + static_cast<char*>(old_out->Data()), | ||
| 830 | + buf_len); | ||
| 831 | + } | ||
| 827 | 832 | ||
| 828 | 833 | // When in CCM mode, EVP_CipherUpdate will fail if the authentication tag is | |
| 829 | 834 | // invalid. In that case, remember the error and throw in final(). | |
@@ -911,11 +916,14 @@ bool CipherBase::Final(std::unique_ptr<BackingStore>* out) { | |||
| 911 | 916 | &out_len) == 1; | |
| 912 | 917 | ||
| 913 | 918 | CHECK_LE(static_cast<size_t>(out_len), (*out)->ByteLength()); | |
| 914 | - if (out_len > 0) { | ||
| 915 | - *out = | ||
| 916 | - BackingStore::Reallocate(env()->isolate(), std::move(*out), out_len); | ||
| 917 | - } else { | ||
| 919 | + if (out_len == 0) { | ||
| 918 | 920 | *out = ArrayBuffer::NewBackingStore(env()->isolate(), 0); | |
| 921 | + } else if (static_cast<size_t>(out_len) != (*out)->ByteLength()) { | ||
| 922 | + std::unique_ptr<BackingStore> old_out = std::move(*out); | ||
| 923 | + *out = ArrayBuffer::NewBackingStore(env()->isolate(), out_len); | ||
| 924 | + memcpy(static_cast<char*>((*out)->Data()), | ||
| 925 | + static_cast<char*>(old_out->Data()), | ||
| 926 | + out_len); | ||
| 919 | 927 | } | |
| 920 | 928 | ||
| 921 | 929 | if (ok && kind_ == kCipher && IsAuthenticatedMode()) { | |
@@ -1015,10 +1023,15 @@ bool PublicKeyCipher::Cipher( | |||
| 1015 | 1023 | } | |
| 1016 | 1024 | ||
| 1017 | 1025 | CHECK_LE(out_len, (*out)->ByteLength()); | |
| 1018 | - if (out_len > 0) | ||
| 1019 | - *out = BackingStore::Reallocate(env->isolate(), std::move(*out), out_len); | ||
| 1020 | - else | ||
| 1026 | + if (out_len == 0) { | ||
| 1021 | 1027 | *out = ArrayBuffer::NewBackingStore(env->isolate(), 0); | |
| 1028 | + } else if (out_len != (*out)->ByteLength()) { | ||
| 1029 | + std::unique_ptr<BackingStore> old_out = std::move(*out); | ||
| 1030 | + *out = ArrayBuffer::NewBackingStore(env->isolate(), out_len); | ||
| 1031 | + memcpy(static_cast<char*>((*out)->Data()), | ||
| 1032 | + static_cast<char*>(old_out->Data()), | ||
| 1033 | + out_len); | ||
| 1034 | + } | ||
| 1022 | 1035 | ||
| 1023 | 1036 | return true; | |
| 1024 | 1037 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,10 +99,15 @@ std::unique_ptr<BackingStore> Node_SignFinal(Environment* env, | |||
| 99 | 99 | EVP_PKEY_sign(pkctx.get(), static_cast<unsigned char*>(sig->Data()), | |
| 100 | 100 | &sig_len, m, m_len)) { | |
| 101 | 101 | CHECK_LE(sig_len, sig->ByteLength()); | |
| 102 | - if (sig_len == 0) | ||
| 102 | + if (sig_len == 0) { | ||
| 103 | 103 | sig = ArrayBuffer::NewBackingStore(env->isolate(), 0); | |
| 104 | - else | ||
| 105 | - sig = BackingStore::Reallocate(env->isolate(), std::move(sig), sig_len); | ||
| 104 | + } else if (sig_len != sig->ByteLength()) { | ||
| 105 | + std::unique_ptr<BackingStore> old_sig = std::move(sig); | ||
| 106 | + sig = ArrayBuffer::NewBackingStore(env->isolate(), sig_len); | ||
| 107 | + memcpy(static_cast<char*>(sig->Data()), | ||
| 108 | + static_cast<char*>(old_sig->Data()), | ||
| 109 | + sig_len); | ||
| 110 | + } | ||
| 106 | 111 | return sig; | |
| 107 | 112 | } | |
| 108 | 113 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -324,8 +324,13 @@ MaybeLocal<Object> New(Isolate* isolate, | |||
| 324 | 324 | CHECK(actual <= length); | |
| 325 | 325 | ||
| 326 | 326 | if (LIKELY(actual > 0)) { | |
| 327 | - if (actual < length) | ||
| 328 | - store = BackingStore::Reallocate(isolate, std::move(store), actual); | ||
| 327 | + if (actual < length) { | ||
| 328 | + std::unique_ptr<BackingStore> old_store = std::move(store); | ||
| 329 | + store = ArrayBuffer::NewBackingStore(isolate, actual); | ||
| 330 | + memcpy(static_cast<char*>(store->Data()), | ||
| 331 | + static_cast<char*>(old_store->Data()), | ||
| 332 | + actual); | ||
| 333 | + } | ||
| 329 | 334 | Local<ArrayBuffer> buf = ArrayBuffer::New(isolate, std::move(store)); | |
| 330 | 335 | Local<Object> obj; | |
| 331 | 336 | if (UNLIKELY(!New(isolate, buf, 0, actual).ToLocal(&obj))) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2029,9 +2029,14 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { | |||
| 2029 | 2029 | ||
| 2030 | 2030 | statistics_.data_received += nread; | |
| 2031 | 2031 | ||
| 2032 | - if (LIKELY(stream_buf_offset_ == 0)) { | ||
| 2032 | + if (LIKELY(stream_buf_offset_ == 0 && | ||
| 2033 | + static_cast<size_t>(nread) != bs->ByteLength())) { | ||
| 2033 | 2034 | // Shrink to the actual amount of used data. | |
| 2034 | - bs = BackingStore::Reallocate(env()->isolate(), std::move(bs), nread); | ||
| 2035 | + std::unique_ptr<BackingStore> old_bs = std::move(bs); | ||
| 2036 | + bs = ArrayBuffer::NewBackingStore(env()->isolate(), nread); | ||
| 2037 | + memcpy(static_cast<char*>(bs->Data()), | ||
| 2038 | + static_cast<char*>(old_bs->Data()), | ||
| 2039 | + nread); | ||
| 2035 | 2040 | } else { | |
| 2036 | 2041 | // This is a very unlikely case, and should only happen if the ReadStart() | |
| 2037 | 2042 | // call in OnStreamAfterWrite() immediately provides data. If that does | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -679,7 +679,13 @@ void EmitToJSStreamListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { | |||
| 679 | 679 | } | |
| 680 | 680 | ||
| 681 | 681 | CHECK_LE(static_cast<size_t>(nread), bs->ByteLength()); | |
| 682 | - bs = BackingStore::Reallocate(isolate, std::move(bs), nread); | ||
| 682 | + if (static_cast<size_t>(nread) != bs->ByteLength()) { | ||
| 683 | + std::unique_ptr<BackingStore> old_bs = std::move(bs); | ||
| 684 | + bs = ArrayBuffer::NewBackingStore(isolate, nread); | ||
| 685 | + memcpy(static_cast<char*>(bs->Data()), | ||
| 686 | + static_cast<char*>(old_bs->Data()), | ||
| 687 | + nread); | ||
| 688 | + } | ||
| 683 | 689 | ||
| 684 | 690 | stream->CallJSOnreadMethod(nread, ArrayBuffer::New(isolate, std::move(bs))); | |
| 685 | 691 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -764,9 +764,13 @@ void UDPWrap::OnRecv(ssize_t nread, | |||
| 764 | 764 | return; | |
| 765 | 765 | } else if (nread == 0) { | |
| 766 | 766 | bs = ArrayBuffer::NewBackingStore(isolate, 0); | |
| 767 | - } else { | ||
| 767 | + } else if (static_cast<size_t>(nread) != bs->ByteLength()) { | ||
| 768 | 768 | CHECK_LE(static_cast<size_t>(nread), bs->ByteLength()); | |
| 769 | - bs = BackingStore::Reallocate(isolate, std::move(bs), nread); | ||
| 769 | + std::unique_ptr<BackingStore> old_bs = std::move(bs); | ||
| 770 | + bs = ArrayBuffer::NewBackingStore(isolate, nread); | ||
| 771 | + memcpy(static_cast<char*>(bs->Data()), | ||
| 772 | + static_cast<char*>(old_bs->Data()), | ||
| 773 | + nread); | ||
| 770 | 774 | } | |
| 771 | 775 | ||
| 772 | 776 | Local<Object> address; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments