Closed Bug 1905875 Opened 5 months ago Closed 2 months ago

Android Components: HttpIconLoader partially loads Icons if content length is not specified

Categories

(Fenix :: General, defect)

Firefox 127
All
Android
defect

Tracking

(firefox128 wontfix, firefox129 wontfix, firefox130 wontfix, firefox131 wontfix, firefox132 wontfix, firefox133 fixed)

RESOLVED FIXED
133 Branch
Tracking Status
firefox128 --- wontfix
firefox129 --- wontfix
firefox130 --- wontfix
firefox131 --- wontfix
firefox132 --- wontfix
firefox133 --- fixed

People

(Reporter: artemchep, Assigned: calu)

References

(Regression)

Details

(Keywords: regression, Whiteboard: [fxdroid] [group4])

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0

Steps to reproduce:

This bug is related to org.mozilla.components:browser-icons:127.0.2.

Extend mozilla.components.browser.icons.BrowserIcons with a custom preparer that points to icons that do not have the Content-Length header in the response. This makes mozilla.components.browser.icons.loader.HttpIconLoader#toIconLoaderResult(...) go the alternative route that sometimes loads icons only partially.

Actual results:

while (inputStream.read(buffer).also { bytesInChunk = it } != -1) {
  outStream.write(buffer, 0, bytesInChunk)
  bytesRead += bytesInChunk  
  
  if (bytesRead > MAX_DOWNLOAD_BYTES || bytesRead > memoryInfoProvider.getAvailMem()) {
    return@useStream IconLoader.Result.NoResult
  }

  if (bytesInChunk < DEFAULT_BUFFER_SIZE) {
    break
  }
}

This snippet assumes that InputStream#read(...) always reads the size of the buffer bytes, unless it's the end of a content. Unfortunately that is not correct, InputStream#read(...) can return any value in range of -1..buffer.size, where only -1 means the end of a content.

This results in an icon sometimes partially loading if the server returns less bytes then requested in a single read.

Expected results:

while (inputStream.read(buffer).also { bytesInChunk = it } != -1) {
  outStream.write(buffer, 0, bytesInChunk)
  bytesRead += bytesInChunk  
  
  if (bytesRead > MAX_DOWNLOAD_BYTES || bytesRead > memoryInfoProvider.getAvailMem()) {
    return@useStream IconLoader.Result.NoResult
  }
}

Additional condition check should be removed.

The severity field is not set for this bug.
:royang, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(royang)
Severity: -- → S4
Flags: needinfo?(royang)
Regressions: 1847372

Hi Cathy, can you please take a look? The reporter thinks that we don't need the check:

  if (bytesInChunk < DEFAULT_BUFFER_SIZE) {
    break
  }
Flags: needinfo?(calu)
Keywords: regression
Regressed by: 1847372
No longer regressions: 1847372

The bug has a release status flag that shows some version of Firefox is affected, thus it will be considered confirmed.

Status: UNCONFIRMED → NEW
Ever confirmed: true

Hey Donal, we use HttpIconLoader for all sorts of images from websites.

I tried just removing the check but the tests fail, I'll try and take a look at the tests soon.

Severity: S4 → S3
Flags: needinfo?(calu)

Set release status flags based on info from the regressing bug 1847372

Hi calu, just resurfacing this based on comment 4 to make sure this didn't fall off your radar.

Flags: needinfo?(calu)
Assignee: nobody → calu
Flags: needinfo?(calu)
Whiteboard: [fxdroid] [group4]
Pushed by calu@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f1b741ea7b4c Fix partially loaded icons when content length is missing r=android-reviewers,owlish
Status: NEW → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 133 Branch

Since nightly and release are affected, beta will likely be affected too.
For more information, please visit BugBot documentation.

The patch landed in nightly and beta is affected.
:calu, is this bug important enough to require an uplift?

  • If yes, please nominate the patch for beta approval.
  • If no, please set status-firefox132 to wontfix.

For more information, please visit BugBot documentation.

Flags: needinfo?(calu)
Flags: needinfo?(calu)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: