| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e057480 commit ebff06b
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,12 +112,15 @@ the `ByteSource::Builder` without releasing it as a `ByteSource`. | |||
| 112 | 112 | ||
| 113 | 113 | ### `ArrayBufferOrViewContents` | |
| 114 | 114 | ||
| 115 | - The `ArrayBufferOfViewContents` class is a helper utility that abstracts | ||
| 115 | + The `ArrayBufferOrViewContents` class is a helper utility that abstracts | ||
| 116 | 116 | `ArrayBuffer`, `TypedArray`, or `DataView` inputs and provides access to | |
| 117 | 117 | their underlying data pointers. It is used extensively through `src/crypto` | |
| 118 | 118 | to make it easier to deal with inputs that allow any `ArrayBuffer`-backed | |
| 119 | 119 | object. | |
| 120 | 120 | ||
| 121 | + The lifetime of `ArrayBufferOrViewContents` should not exceed the | ||
| 122 | + lifetime of its input. | ||
| 123 | + | ||
| 121 | 124 | ### Key objects | |
| 122 | 125 | ||
| 123 | 126 | Most crypto operations involve the use of keys -- cryptographic inputs | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -523,9 +523,8 @@ void CipherBase::InitIv(const FunctionCallbackInfo<Value>& args) { | |||
| 523 | 523 | if (UNLIKELY(key_buf.size() > INT_MAX)) | |
| 524 | 524 | return THROW_ERR_OUT_OF_RANGE(env, "key is too big"); | |
| 525 | 525 | ||
| 526 | - ArrayBufferOrViewContents<unsigned char> iv_buf; | ||
| 527 | - if (!args[2]->IsNull()) | ||
| 528 | - iv_buf = ArrayBufferOrViewContents<unsigned char>(args[2]); | ||
| 526 | + ArrayBufferOrViewContents<unsigned char> iv_buf( | ||
| 527 | + !args[2]->IsNull() ? args[2] : Local<Value>()); | ||
| 529 | 528 | ||
| 530 | 529 | if (UNLIKELY(!iv_buf.CheckSizeInt32())) | |
| 531 | 530 | return THROW_ERR_OUT_OF_RANGE(env, "iv is too big"); | |
@@ -1048,12 +1047,10 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) { | |||
| 1048 | 1047 | return THROW_ERR_OSSL_EVP_INVALID_DIGEST(env); | |
| 1049 | 1048 | } | |
| 1050 | 1049 | ||
| 1051 | - ArrayBufferOrViewContents<unsigned char> oaep_label; | ||
| 1052 | - if (!args[offset + 3]->IsUndefined()) { | ||
| 1053 | - oaep_label = ArrayBufferOrViewContents<unsigned char>(args[offset + 3]); | ||
| 1054 | - if (UNLIKELY(!oaep_label.CheckSizeInt32())) | ||
| 1055 | - return THROW_ERR_OUT_OF_RANGE(env, "oaep_label is too big"); | ||
| 1056 | - } | ||
| 1050 | + ArrayBufferOrViewContents<unsigned char> oaep_label( | ||
| 1051 | + !args[offset + 3]->IsUndefined() ? args[offset + 3] : Local<Value>()); | ||
| 1052 | + if (UNLIKELY(!oaep_label.CheckSizeInt32())) | ||
| 1053 | + return THROW_ERR_OUT_OF_RANGE(env, "oaep_label is too big"); | ||
| 1057 | 1054 | ||
| 1058 | 1055 | std::unique_ptr<BackingStore> out; | |
| 1059 | 1056 | if (!Cipher<operation, EVP_PKEY_cipher_init, EVP_PKEY_cipher>( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -696,24 +696,30 @@ template <typename T> | |||
| 696 | 696 | class ArrayBufferOrViewContents { | |
| 697 | 697 | public: | |
| 698 | 698 | ArrayBufferOrViewContents() = default; | |
| 699 | + ArrayBufferOrViewContents(const ArrayBufferOrViewContents&) = delete; | ||
| 700 | + void operator=(const ArrayBufferOrViewContents&) = delete; | ||
| 699 | 701 | ||
| 700 | 702 | inline explicit ArrayBufferOrViewContents(v8::Local<v8::Value> buf) { | |
| 703 | + if (buf.IsEmpty()) { | ||
| 704 | + return; | ||
| 705 | + } | ||
| 706 | + | ||
| 701 | 707 | CHECK(IsAnyByteSource(buf)); | |
| 702 | 708 | if (buf->IsArrayBufferView()) { | |
| 703 | 709 | auto view = buf.As<v8::ArrayBufferView>(); | |
| 704 | 710 | offset_ = view->ByteOffset(); | |
| 705 | 711 | length_ = view->ByteLength(); | |
| 706 | - store_ = view->Buffer()->GetBackingStore(); | ||
| 712 | + data_ = view->Buffer()->Data(); | ||
| 707 | 713 | } else if (buf->IsArrayBuffer()) { | |
| 708 | 714 | auto ab = buf.As<v8::ArrayBuffer>(); | |
| 709 | 715 | offset_ = 0; | |
| 710 | 716 | length_ = ab->ByteLength(); | |
| 711 | - store_ = ab->GetBackingStore(); | ||
| 717 | + data_ = ab->Data(); | ||
| 712 | 718 | } else { | |
| 713 | 719 | auto sab = buf.As<v8::SharedArrayBuffer>(); | |
| 714 | 720 | offset_ = 0; | |
| 715 | 721 | length_ = sab->ByteLength(); | |
| 716 | - store_ = sab->GetBackingStore(); | ||
| 722 | + data_ = sab->Data(); | ||
| 717 | 723 | } | |
| 718 | 724 | } | |
| 719 | 725 | ||
@@ -723,7 +729,7 @@ class ArrayBufferOrViewContents { | |||
| 723 | 729 | // length is zero, so we have to return something. | |
| 724 | 730 | if (size() == 0) | |
| 725 | 731 | return &buf; | |
| 726 | - return reinterpret_cast<T*>(store_->Data()) + offset_; | ||
| 732 | + return reinterpret_cast<T*>(data_) + offset_; | ||
| 727 | 733 | } | |
| 728 | 734 | ||
| 729 | 735 | inline T* data() { | |
@@ -732,7 +738,7 @@ class ArrayBufferOrViewContents { | |||
| 732 | 738 | // length is zero, so we have to return something. | |
| 733 | 739 | if (size() == 0) | |
| 734 | 740 | return &buf; | |
| 735 | - return reinterpret_cast<T*>(store_->Data()) + offset_; | ||
| 741 | + return reinterpret_cast<T*>(data_) + offset_; | ||
| 736 | 742 | } | |
| 737 | 743 | ||
| 738 | 744 | inline size_t size() const { return length_; } | |
@@ -772,7 +778,14 @@ class ArrayBufferOrViewContents { | |||
| 772 | 778 | T buf = 0; | |
| 773 | 779 | size_t offset_ = 0; | |
| 774 | 780 | size_t length_ = 0; | |
| 775 | - std::shared_ptr<v8::BackingStore> store_; | ||
| 781 | + void* data_ = nullptr; | ||
| 782 | + | ||
| 783 | + // Declaring operator new and delete as deleted is not spec compliant. | ||
| 784 | + // Therefore declare them private instead to disable dynamic alloc | ||
| 785 | + void* operator new(size_t); | ||
| 786 | + void* operator new[](size_t); | ||
| 787 | + void operator delete(void*); | ||
| 788 | + void operator delete[](void*); | ||
| 776 | 789 | }; | |
| 777 | 790 | ||
| 778 | 791 | v8::MaybeLocal<v8::Value> EncodeBignum( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments