@stoprocent/noble 2.3.13 → 2.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1235,6 +1235,12 @@ Hci.prototype.processLeAdvertisingReport = function (numReports, data) {
1235
1235
  Hci.prototype.processLeExtendedAdvertisingReport = function (numReports, data) {
1236
1236
  try {
1237
1237
  for (let i = 0; i < numReports; i++) {
1238
+ if (data.length < 24) {
1239
+ console.warn(
1240
+ `processLeExtendedAdvertisingReport: Caught illegal packet (too short: ${data.length} < 24)`
1241
+ );
1242
+ break;
1243
+ }
1238
1244
  const type = data.readUInt16LE(0);
1239
1245
  const addressType = data.readUInt8(2) === 0x01 ? 'random' : 'public';
1240
1246
  const address = data
@@ -1258,6 +1264,12 @@ Hci.prototype.processLeExtendedAdvertisingReport = function (numReports, data) {
1258
1264
  .reverse()
1259
1265
  .join(':');
1260
1266
  const eirLength = data.readUInt8(23);
1267
+ if (data.length < 24 + eirLength) {
1268
+ console.warn(
1269
+ `processLeExtendedAdvertisingReport: Caught illegal packet (eir length ${eirLength} exceeds remaining ${data.length - 24})`
1270
+ );
1271
+ break;
1272
+ }
1261
1273
  const eir = data.slice(24);
1262
1274
 
1263
1275
  debug(`\t\t\ttype = ${type}`);
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "license": "MIT",
7
7
  "name": "@stoprocent/noble",
8
8
  "description": "A Node.js BLE (Bluetooth Low Energy) central library.",
9
- "version": "2.3.13",
9
+ "version": "2.3.14",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/stoprocent/noble.git"
@@ -1891,8 +1891,12 @@ describe('hci-socket hci', () => {
1891
1891
  describe('processLeExtendedAdvertisingReport', () => {
1892
1892
  it('should emit without error', () => {
1893
1893
  const count = 2;
1894
- const data1 = Buffer.from([0, 1, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0]);
1895
- const data2 = Buffer.from([1, 0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 4, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]);
1894
+ const eir1 = Buffer.from([0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17]);
1895
+ const header1 = Buffer.from([0, 1, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, eir1.length]);
1896
+ const data1 = Buffer.concat([header1, eir1]);
1897
+ const eir2 = Buffer.from([0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27]);
1898
+ const header2 = Buffer.from([1, 0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 4, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, eir2.length]);
1899
+ const data2 = Buffer.concat([header2, eir2]);
1896
1900
  const data = Buffer.concat([data1, data2]);
1897
1901
  const callback = sinon.spy();
1898
1902
 
@@ -1904,7 +1908,9 @@ describe('hci-socket hci', () => {
1904
1908
 
1905
1909
  it('should emit only once with random address', () => {
1906
1910
  const count = 1;
1907
- const data = Buffer.from([0, 1, 1, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]);
1911
+ const eir = Buffer.from([0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17]);
1912
+ const header = Buffer.from([0, 1, 1, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, eir.length]);
1913
+ const data = Buffer.concat([header, eir]);
1908
1914
  const callback = sinon.spy();
1909
1915
 
1910
1916
  hci.on('leExtendedAdvertisingReport', callback);
@@ -1915,7 +1921,9 @@ describe('hci-socket hci', () => {
1915
1921
 
1916
1922
  it('should emit only once with public address', () => {
1917
1923
  const count = 1;
1918
- const data = Buffer.from([0, 1, 2, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]);
1924
+ const eir = Buffer.from([0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17]);
1925
+ const header = Buffer.from([0, 1, 2, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, eir.length]);
1926
+ const data = Buffer.concat([header, eir]);
1919
1927
  const callback = sinon.spy();
1920
1928
 
1921
1929
  hci.on('leExtendedAdvertisingReport', callback);
@@ -1937,6 +1945,41 @@ describe('hci-socket hci', () => {
1937
1945
  assert.notCalled(callback);
1938
1946
  expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('illegal packet'));
1939
1947
  });
1948
+
1949
+ it('should ignore too-short extended report without throwing', () => {
1950
+ const count = 1;
1951
+ const data = Buffer.alloc(10);
1952
+ const callback = sinon.spy();
1953
+
1954
+ const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1955
+
1956
+ hci.on('leExtendedAdvertisingReport', callback);
1957
+ hci.processLeExtendedAdvertisingReport(count, data);
1958
+
1959
+ assert.notCalled(callback);
1960
+ expect(consoleSpy.mock.calls.some((call) => String(call[0]).includes('too short'))).toBe(true);
1961
+ consoleSpy.mockRestore();
1962
+ });
1963
+
1964
+ it('should ignore extended report with oversized eir length', () => {
1965
+ const count = 1;
1966
+ const data = Buffer.from([
1967
+ 0, 1, 2, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa,
1968
+ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
1969
+ 200, // eirLength larger than remaining bytes
1970
+ 0x01, 0x02, 0x03,
1971
+ ]);
1972
+ const callback = sinon.spy();
1973
+
1974
+ const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1975
+
1976
+ hci.on('leExtendedAdvertisingReport', callback);
1977
+ hci.processLeExtendedAdvertisingReport(count, data);
1978
+
1979
+ assert.notCalled(callback);
1980
+ expect(consoleSpy.mock.calls.some((call) => String(call[0]).includes('eir length'))).toBe(true);
1981
+ consoleSpy.mockRestore();
1982
+ });
1940
1983
  });
1941
1984
 
1942
1985
  it('processLeConnUpdateComplete', () => {