@basmilius/apple-airplay 0.13.2 → 0.13.4

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.
Files changed (2) hide show
  1. package/dist/index.mjs +25 -15
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -12926,21 +12926,26 @@ function chacha20Decrypt(state, data) {
12926
12926
  const result = [];
12927
12927
  let offset = 0;
12928
12928
  let readCount = state.readCount ?? 0;
12929
- while (offset < data.length) {
12930
- if (offset + 2 > data.length) return false;
12931
- const frameLength = data.readUInt16LE(offset);
12932
- offset += 2;
12933
- if (frameLength === 0 || frameLength > 65535) return false;
12934
- const end = offset + frameLength + 16;
12935
- if (end > data.length) return false;
12936
- const ciphertext = data.subarray(offset, offset + frameLength);
12937
- const authTag = data.subarray(offset + frameLength, end);
12938
- offset = end;
12939
- const plaintext = Chacha20.decrypt(state.readKey, nonce(readCount++), Buffer.from(Uint16Array.of(frameLength).buffer.slice(0, 2)), ciphertext, authTag);
12940
- result.push(plaintext);
12941
- }
12942
- state.readCount = readCount;
12943
- return Buffer.concat(result);
12929
+ try {
12930
+ while (offset < data.length) {
12931
+ if (offset + 2 > data.length) return false;
12932
+ const frameLength = data.readUInt16LE(offset);
12933
+ offset += 2;
12934
+ if (frameLength === 0) throw new Error("Corrupt encrypted frame: zero-length frame");
12935
+ const end = offset + frameLength + 16;
12936
+ if (end > data.length) return false;
12937
+ const ciphertext = data.subarray(offset, offset + frameLength);
12938
+ const authTag = data.subarray(offset + frameLength, end);
12939
+ offset = end;
12940
+ const plaintext = Chacha20.decrypt(state.readKey, nonce(readCount++), Buffer.from(Uint16Array.of(frameLength).buffer.slice(0, 2)), ciphertext, authTag);
12941
+ result.push(plaintext);
12942
+ }
12943
+ state.readCount = readCount;
12944
+ return Buffer.concat(result);
12945
+ } catch (err) {
12946
+ state.readCount = readCount;
12947
+ throw err;
12948
+ }
12944
12949
  }
12945
12950
  /**
12946
12951
  * Encrypts data using AirPlay's ChaCha20-Poly1305 frame format.
@@ -13790,6 +13795,8 @@ var DataStream = class extends BaseStream {
13790
13795
  if (command === "sync") this.reply(parseHeaderSeqno(header));
13791
13796
  }
13792
13797
  } catch (err) {
13798
+ this.#encryptedBuffer = Buffer.alloc(0);
13799
+ this.#buffer = Buffer.alloc(0);
13793
13800
  this.context.logger.error("[data]", "onStreamData()", err);
13794
13801
  this.emit("error", err);
13795
13802
  }
@@ -14203,6 +14210,8 @@ var EventStream = class extends BaseStream {
14203
14210
  await this.#handle(result.method, result.path, result.headers, result.body);
14204
14211
  }
14205
14212
  } catch (err) {
14213
+ this.#encryptedBuffer = Buffer.alloc(0);
14214
+ this.#buffer = Buffer.alloc(0);
14206
14215
  this.context.logger.error("[event]", "onStreamData()", err);
14207
14216
  this.emit("error", err);
14208
14217
  }
@@ -14872,6 +14881,7 @@ var Protocol = class {
14872
14881
  timescale: 0
14873
14882
  } });
14874
14883
  } catch (err) {
14884
+ this.#stopPlayUrlFeedback();
14875
14885
  try {
14876
14886
  await this.#controlStream.teardown(`/${this.#controlStream.sessionId}`);
14877
14887
  } catch (teardownErr) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@basmilius/apple-airplay",
3
3
  "description": "Implementation of Apple's AirPlay2 in Node.js.",
4
- "version": "0.13.2",
4
+ "version": "0.13.4",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -47,10 +47,10 @@
47
47
  }
48
48
  },
49
49
  "dependencies": {
50
- "@basmilius/apple-common": "0.13.2",
51
- "@basmilius/apple-encoding": "0.13.2",
52
- "@basmilius/apple-encryption": "0.13.2",
53
- "@basmilius/apple-rtsp": "0.13.2"
50
+ "@basmilius/apple-common": "0.13.4",
51
+ "@basmilius/apple-encoding": "0.13.4",
52
+ "@basmilius/apple-encryption": "0.13.4",
53
+ "@basmilius/apple-rtsp": "0.13.4"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@bufbuild/buf": "^1.66.1",