Skip to content

ngclient requestsfetcher result when length > max_length #1502

Closed

Description

@jku

If RequestsFetcher downloads a URL and the content is longer than max_length, RequestFetcher does not raise but returns max_length bytes.

This is not a fatal issue but leads to a strange situation where the TargetFile.verify_length_and_hashes() actually succeeds the length check (because it got exactly max_length bytes) and only fails the hashes check.

I think RequestsFetcher should either

  1. raise when the content is longer than max_length or
  2. not try to return exactly max_length so that Fetcher itself can raise if length is incorrect. This would mean
    • RequestsFetcher: not doing the read_amount = min(self.chunk_size, max_length - bytes_received) thing
    • RequestsFetcher: not checking if bytes_received >= max_length in the end of the loop
    • Fetcher: moving the DownloadLengthMismatchError check in download_file() so it happens inside the loop

I only a had a quick look but 2 seems like the better solution: less code, more correct implementation, and only a maximum of chunk_size more downloading if the length is incorrect?

Activity

  1. changed the title [-]ngclient requestsfetcher[/-] [+]ngclient requestsfetcher result when length > max_length[/+] on Jul 20, 2021
  2. sechkova commented on Jul 23, 2021

    @sechkova
    Contributor

    By our own definition fetch "Ensures the length of the downloaded data is up to 'max_length'." Meaning that if we implement 2 we are not complying with our own API. Or we can update the API too.

  3. added
    backlog
    on Jul 28, 2021
  4. added this to the Sprint 5 milestone on Jul 28, 2021
  5. modified the milestones: Sprint 5, Sprint 6 on Aug 18, 2021
  6. removed
    backlog
    on Aug 18, 2021
  7. modified the milestones: Sprint 6, Sprint 7 on Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions