Address the CodeRabbit review: inbound SMS, binary payloads and untrusted input
This commit is contained in:
@@ -50,6 +50,12 @@ describe('LATIN1', () => {
|
||||
assert.equal(encodings.LATIN1.decode(Buffer.from(bytes)), str);
|
||||
}
|
||||
});
|
||||
|
||||
test('carries every octet through unchanged, which is what makes it the binary codec', () => {
|
||||
const every = Buffer.from(Array.from({ length: 256 }, (_, byte) => byte));
|
||||
|
||||
assert.deepEqual(encodings.LATIN1.encode(encodings.LATIN1.decode(every)), every);
|
||||
});
|
||||
});
|
||||
|
||||
describe('UCS2', () => {
|
||||
@@ -78,6 +84,15 @@ describe('UCS2', () => {
|
||||
|
||||
assert.deepEqual(buffer, Buffer.from([0x00, 0x20]));
|
||||
});
|
||||
|
||||
// swap16() throws ERR_INVALID_BUFFER_SIZE on an odd octet count, and sm_length is peer-controlled.
|
||||
test('drops an incomplete trailing octet instead of throwing', () => {
|
||||
const odd = Buffer.from([0x00, 0x41, 0x00, 0x42, 0x00]);
|
||||
|
||||
assert.equal(encodings.UCS2.decode(odd), 'AB');
|
||||
assert.equal(encodings.UCS2.decode(Buffer.from([0x41])), '');
|
||||
assert.deepEqual(odd, Buffer.from([0x00, 0x41, 0x00, 0x42, 0x00]));
|
||||
});
|
||||
});
|
||||
|
||||
describe('detect()', () => {
|
||||
@@ -111,6 +126,12 @@ describe('encodingByDataCoding()', () => {
|
||||
assert.equal(encodingByDataCoding(0xF0), 'ASCII');
|
||||
});
|
||||
|
||||
test('resolves the 8-bit binary codings to the codec that keeps every octet', () => {
|
||||
for (const dataCoding of [0x02, 0x04, 0x14, 0xF4, 0xF7]) {
|
||||
assert.equal(encodingByDataCoding(dataCoding), 'LATIN1');
|
||||
}
|
||||
});
|
||||
|
||||
test('falls back to ASCII for alphabets it has no codec for', () => {
|
||||
assert.equal(encodingByDataCoding(0x05), 'ASCII');
|
||||
assert.equal(encodingByDataCoding(0x0E), 'ASCII');
|
||||
|
||||
Reference in New Issue
Block a user