[Bug]: HTTP Range Responses not within spec

Aperta
#8,371 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android
Ambito
networking

Direzione di ricerca

Esegui la riproduzione fornita con pnpm i, pnpm build, pnpm cap sync android e pnpm cap run android, quindi ispeziona l’implementazione dell’Android Web Server che gestisce le richieste HTTP Range. Verifica i dati della risposta della richiesta di esempio rispetto ai relativi header Content-Length e Content-Range; il lavoro è completato quando lo stream viene troncato all’intervallo richiesto oppure gli header descrivono accuratamente il resto restituito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

triage
Capacitor Version

8.1.0

Other API Details

Platforms Affected
  • iOS
  • Android
  • Web
Current Behavior

This issue has been reported: https://github.com/ionic-team/capacitor/issues/7151#issuecomment-1897113728

When constructing the response for an HTTP Range request, the InputStream is not properly truncated at the end of the requested range. This results in the response including data from the specified start index, all the way to the end of the file.

The results of this failed truncation are as follows:

  • The Content-Length response header gives a byte length that would be correct if the InputStream was truncated
  • The Content-Range response header gives a byte range that would be correct if the InputStream was truncated

From my understanding of the HTTP Range spec, if the server plans to send the remainder of the file in the response (which is the current behavior of the Capacitor implementation), the Content-Length and Content-Range must be updated to reflect the extra returned length and ending byte range (length - 1).

This appears to cause issues specifically with the PMTiles decoder since it appears to rely on the response headers to understand how much data it received.

Reproduction Steps
  1. Install dependencies and build app with pnpm (crucial for patches to apply)
pnpm i
pnpm build
pnpm cap sync android
pnpm cap run android
  1. Using the demo app, observe a cstat.pmtiles request from within Chrome Devtools.
  2. You will see a Content-Length header in the response.
  3. Convert the Content-Length value to hexadecimal
  4. View the Response data tab in Devtools
  5. Go to the Hexadecimal index you calculated in Step 3.
  6. See that there is lots of data returned that exceeds the Content-Length.
  7. You will see that the data continues to the end of the file (index = totalFileLength - startRange - 1 => Convert to Hex)
Example

Request Range: bytes=850902-889367
Response Content-Length Header: 38466 (0x00009642)
Response Content-Range Header: bytes 850902-889367/3949417

Response Data @ 0x00009642

Image

Response Data @ 0x002F4792 (See step 7: 3949417-850902-1)

Image
Expected Behavior

The stream is properly truncated at the specified byte index or the response headers match the fact that the remainder of the file is sent. Ideally the stream is properly truncated to minimize large data transfer.

Project Reproduction

https://github.com/bwees/range-request-capacitor-repro/tree/fix/lowercase-range

UPDATE: March 3 17:00 UTC, the example project was broken and has since been fixed

Additional Information

The provided project branch includes a pnpm patch that resolves issues that are fixed in #8368. This is needed to properly debug this problem as otherwise the range response headers are not sent.

I also took multiple attempts at creating a PR to solve this issue but could not get the stream to properly truncate without a ERR:FAILED error being thrown or the Content-Length header being overridden before response to the client. Maybe someone more versed in the Web Server implementation has some insight but I was not able to solve it

Lingua principale
TypeScript
Stelle
16.7k
Fork
1.3k
Merge medio
3g 10h
PR unite (30g)
10

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ionic-team/capacitor

Tutte le issue di ionic-team/capacitor

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.