Skip to content

Comments

fix: validate wheel files in a RAM friendly way#183

Closed
ralbertazzi wants to merge 1 commit intopypa:mainfrom
ralbertazzi:feat/validate-zip-ram-friendly
Closed

fix: validate wheel files in a RAM friendly way#183
ralbertazzi wants to merge 1 commit intopypa:mainfrom
ralbertazzi:feat/validate-zip-ram-friendly

Conversation

@ralbertazzi
Copy link

See python-poetry/poetry#7983

Content validation of a wheel record currently loads the entire file in memory with a self._zipfile.read(item). This is extremely inefficient from big wheels (the well known PyTorch has now >2 GB wheel files) and leads to an extremely high RAM consumption. This PR fixes this behaviour by reading the zip file content in a buffered way, as other parts of the codebase are already doing. Unfortunately this required a small change to some signatures.

f"In {self._zipfile.filename}, hash / size of {item.filename} didn't match RECORD"
)
with self._zipfile.open(item, "r") as stream:
if not record.validate(cast("BinaryIO", stream), item.file_size):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(straying into changes beyond the scope of this MR: but so far as I can see this repository could use IO[bytes] everywhere it currently uses BinaryIO which would save some casting)

@pradyunsg
Copy link
Member

I've filed #185 for this to have an issue associated with the PR; in case there's any high-level details to discuss. There likely aren't but it can't hurt to have an issue to close and drive not-PR-specific discussions into.

Other than that, I don't think making a backwards incompatible change is necessary here -- I've filed #186 that does not contain backwards incompatible API changes and instead adds a new method and deprecates the (problematic) RecordEntry.validate(data) method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants