Skip to content

fix: update regex for multipart content-type parsing in multipleRange #9064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2025

Conversation

beyondkmp
Copy link
Collaborator

@beyondkmp beyondkmp commented Apr 27, 2025

The Content-Type response is as follows: Content-Type: multipart/byteranges; boundary=799ddd5a-943e-4e22-981d-e32596ca39d2. The boundary can have a space before it or no space at all.
Here's the rfc:
https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.1.1
image

Issue

Currently, the check only accounts for cases where there is a space. If some servers return a response without a space, it will cause incremental downloads to fail.

Error Info

17:13:29.256 > Full: 92,770.98 KB, To download: 19,742.1 KB (21%)
17:13:29.633 > Cannot download differentially, fallback to full download: Error: Content-Type "multipart/byteranges" is expected, but got "multipart/byteranges;boundary=e888c103-165d-4ec1-9b6f-eca722ac9b10"
    at ClientRequest.<anonymous> (C:\Users\payne\AppData\Local\Programs\Cherry Studio\resources\app.asar\node_modules\electron-updater\out\differentialDownloader\multipleRangeDownloader.js:80:20)
    at ClientRequest.emit (node:events:531:35)
    at SimpleURLLoaderWrapper.<anonymous> (node:electron/js2c/browser_init:2:114720)
    at SimpleURLLoaderWrapper.emit (node:events:519:28)
17:13:34.288 > New version 1.2.9 has been downloaded to C:\Users\payne\AppData\Local\cherrystudio-updater\pending\Cherry-Studio-1.2.9-x64-setup.exe

How to fix

Welcome to Node.js v22.14.0.
Type ".help" for more information.
> /^multipart\/.+?\s*;\s*boundary=(?:"([^"]+)"|([^\s";]+))\s*$/i.exec("multipart/byteranges;boundary=799ddd5a-943e-4e22-981d-e32596ca39d2")
[
  'multipart/byteranges;boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  undefined,
  '799ddd5a-943e-4e22-981d-e32596ca39d2',
  index: 0,
  input: 'multipart/byteranges;boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  groups: undefined
]
> /^multipart\/.+?\s*;\s*boundary=(?:"([^"]+)"|([^\s";]+))\s*$/i.exec("multipart/byteranges; boundary=799ddd5a-943e-4e22-981d-e32596ca39d2")
[
  'multipart/byteranges; boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  undefined,
  '799ddd5a-943e-4e22-981d-e32596ca39d2',
  index: 0,
  input: 'multipart/byteranges; boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  groups: undefined
]

might fix #9063

Copy link

changeset-bot bot commented Apr 27, 2025

🦋 Changeset detected

Latest commit: 350adb3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
electron-updater Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mmaietta
Copy link
Collaborator

Just to double check, were all permutations of Content-Type tested for this? (I'm always most cautious with electron-updater changes)

@beyondkmp
Copy link
Collaborator Author

I currently can not modify the Nginx code, so I cannot directly mock a real download scenario for testing.

However, this regex has been tested against all possible return scenarios, and there were no issues. The test results are as follows.

> /^multipart\/.+?\s*;\s*boundary=(?:"([^"]+)"|([^\s";]+))\s*$/i.exec("multipart/byteranges;boundary=799ddd5a-943e-4e22-981d-e32596ca39d2")
[ 'multipart/byteranges;boundary=799ddd5a-943e-4e22-981d-e32596ca39d2', undefined, '799ddd5a-943e-4e22-981d...
  'multipart/byteranges;boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  undefined,
  '799ddd5a-943e-4e22-981d-e32596ca39d2',
  index: 0,
  input: 'multipart/byteranges;boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  groups: undefined
]
> /^multipart\/.+?\s*;\s*boundary=(?:"([^"]+)"|([^\s";]+))\s*$/i.exec("multipart/byteranges;Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2")
[ 'multipart/byteranges;Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2', undefined, '799ddd5a-943e-4e22-981d...
  'multipart/byteranges;Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  undefined,
  '799ddd5a-943e-4e22-981d-e32596ca39d2',
  index: 0,
  input: 'multipart/byteranges;Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  groups: undefined
]
> /^multipart\/.+?\s*;\s*boundary=(?:"([^"]+)"|([^\s";]+))\s*$/i.exec("multipart/byterangeS;Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2")
[ 'multipart/byterangeS;Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2', undefined, '799ddd5a-943e-4e22-981d...
  'multipart/byterangeS;Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  undefined,
  '799ddd5a-943e-4e22-981d-e32596ca39d2',
  index: 0,
  input: 'multipart/byterangeS;Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  groups: undefined
]
> /^multipart\/.+?\s*;\s*boundary=(?:"([^"]+)"|([^\s";]+))\s*$/i.exec("multipart/byterangeS; Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2")
[ 'multipart/byterangeS; Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2', undefined, '799ddd5a-943e-4e22-981...
  'multipart/byterangeS; Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  undefined,
  '799ddd5a-943e-4e22-981d-e32596ca39d2',
  index: 0,
  input: 'multipart/byterangeS; Boundary=799ddd5a-943e-4e22-981d-e32596ca39d2',
  groups: undefined
]
>
@beyondkmp beyondkmp merged commit 444b791 into electron-userland:master Apr 30, 2025
49 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants