buffer, crypto: fix default encoding regression
The default encoding is 'buffer'. When the input is a string, treat it as 'binary'. Fixes the following assertion: node: ../src/string_bytes.cc:309: static size_t node::StringBytes::StorageSize(v8::Handle<v8::Value>, node::encoding): Assertion `0 && "buffer encoding specified but string provided"' failed. Introduced in 64fc34b2. Fixes #5482.
This commit is contained in:
parent
4cd643ee2d
commit
f59ab10a64
@ -220,7 +220,8 @@ size_t StringBytes::Write(char* buf,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case BINARY: {
|
case BINARY:
|
||||||
|
case BUFFER: {
|
||||||
// TODO(isaacs): THIS IS AWFUL!!!
|
// TODO(isaacs): THIS IS AWFUL!!!
|
||||||
uint16_t* twobytebuf = new uint16_t[buflen];
|
uint16_t* twobytebuf = new uint16_t[buflen];
|
||||||
|
|
||||||
@ -248,10 +249,6 @@ size_t StringBytes::Write(char* buf,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case BUFFER:
|
|
||||||
assert(0 && "buffer encoding specified, but string provided");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(0 && "unknown encoding");
|
assert(0 && "unknown encoding");
|
||||||
break;
|
break;
|
||||||
@ -277,6 +274,7 @@ size_t StringBytes::StorageSize(Handle<Value> val, enum encoding encoding) {
|
|||||||
|
|
||||||
switch (encoding) {
|
switch (encoding) {
|
||||||
case BINARY:
|
case BINARY:
|
||||||
|
case BUFFER:
|
||||||
case ASCII:
|
case ASCII:
|
||||||
data_size = str->Length();
|
data_size = str->Length();
|
||||||
break;
|
break;
|
||||||
@ -305,10 +303,6 @@ size_t StringBytes::StorageSize(Handle<Value> val, enum encoding encoding) {
|
|||||||
data_size = str->Length() / 2;
|
data_size = str->Length() / 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BUFFER:
|
|
||||||
assert(0 && "buffer encoding specified but string provided");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(0 && "unknown encoding");
|
assert(0 && "unknown encoding");
|
||||||
break;
|
break;
|
||||||
@ -331,6 +325,7 @@ size_t StringBytes::Size(Handle<Value> val, enum encoding encoding) {
|
|||||||
|
|
||||||
switch (encoding) {
|
switch (encoding) {
|
||||||
case BINARY:
|
case BINARY:
|
||||||
|
case BUFFER:
|
||||||
case ASCII:
|
case ASCII:
|
||||||
data_size = str->Length();
|
data_size = str->Length();
|
||||||
break;
|
break;
|
||||||
@ -357,10 +352,6 @@ size_t StringBytes::Size(Handle<Value> val, enum encoding encoding) {
|
|||||||
data_size = str->Length() / 2;
|
data_size = str->Length() / 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BUFFER:
|
|
||||||
assert(0 && "buffer encoding specified by string provided");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(0 && "unknown encoding");
|
assert(0 && "unknown encoding");
|
||||||
break;
|
break;
|
||||||
|
@ -979,3 +979,8 @@ assert.throws(function() {
|
|||||||
assert.equal(buf.slice(0, -i), s.slice(0, -i));
|
assert.equal(buf.slice(0, -i), s.slice(0, -i));
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// Regression test for #5482: should throw but not assert in C++ land.
|
||||||
|
assert.throws(function() {
|
||||||
|
Buffer('', 'buffer');
|
||||||
|
}, TypeError);
|
||||||
|
@ -887,3 +887,10 @@ assert.throws(function() {
|
|||||||
try { d.final('xxx') } catch (e) { /* Ignore. */ }
|
try { d.final('xxx') } catch (e) { /* Ignore. */ }
|
||||||
try { d.final('xxx') } catch (e) { /* Ignore. */ }
|
try { d.final('xxx') } catch (e) { /* Ignore. */ }
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// Regression test for #5482: string to Cipher#update() should not assert.
|
||||||
|
(function() {
|
||||||
|
var c = crypto.createCipher('aes192', '0123456789abcdef');
|
||||||
|
c.update('update');
|
||||||
|
c.final();
|
||||||
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user