| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d2c9c07 commit bb1aea8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,7 +124,8 @@ Hash.prototype.copy = function copy(options) { | |||
| 124 | 124 | }; | |
| 125 | 125 | ||
| 126 | 126 | Hash.prototype._transform = function _transform(chunk, encoding, callback) { | |
| 127 | - this[kHandle].update(chunk, encoding); | ||
| 127 | + if (!this[kHandle].update(chunk, encoding)) | ||
| 128 | + return callback(new ERR_CRYPTO_HASH_UPDATE_FAILED()); | ||
| 128 | 129 | callback(); | |
| 129 | 130 | }; | |
| 130 | 131 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,32 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Flags: --expose-internals | ||
| 4 | + | ||
| 5 | + const common = require('../common'); | ||
| 6 | + if (!common.hasCrypto) common.skip('missing crypto'); | ||
| 7 | + | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + const crypto = require('crypto'); | ||
| 10 | + const { kHandle } = require('internal/crypto/util'); | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * This test verifies that the Hash stream properly surfaces an error | ||
| 14 | + * when the underlying native update fails. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | + const h = crypto.createHash('sha256'); | ||
| 18 | + | ||
| 19 | + // Simulate native update failure by replacing the internal handle | ||
| 20 | + const fakeHandle = { | ||
| 21 | + update: () => false, | ||
| 22 | + digest: () => Buffer.from('') | ||
| 23 | + }; | ||
| 24 | + | ||
| 25 | + h[kHandle] = fakeHandle; | ||
| 26 | + | ||
| 27 | + h.on('error', common.mustCall((err) => { | ||
| 28 | + assert.strictEqual(err.code, 'ERR_CRYPTO_HASH_UPDATE_FAILED'); | ||
| 29 | + })); | ||
| 30 | + | ||
| 31 | + h.write('test data'); | ||
| 32 | + h.end(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments