Skip to content

fix[codegen]: fix bytes copying routines for 0-length case #4649

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

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented May 16, 2025

What I did

per title. per #4645 and #4644 (and their associated security advisories) it is difficult, but not impossible, to construct an empty bytestring which has side effects. for hygiene, don't fastpath out the side effects for zero-length bytestrings

How I did it

How to verify it

Commit message

per title. as in the referenced pull requests and security advisories,
it is difficult, but not impossible, to construct an empty bytestring
which has side effects. in this commit, don't fastpath out the side
effects for zero-length bytestrings

references:
- https://github.com/vyperlang/vyper/pull/4644
- https://github.com/vyperlang/vyper/security/advisories/GHSA-qhr6-mgqr-mchm
- https://github.com/vyperlang/vyper/pull/4645
- https://github.com/vyperlang/vyper/security/advisories/GHSA-3vcg-j39x-cwfm

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

Copy link

codecov bot commented May 16, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 92.53%. Comparing base (1fdfd69) to head (f7940f0).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
vyper/codegen/core.py 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4649      +/-   ##
==========================================
- Coverage   92.53%   92.53%   -0.01%     
==========================================
  Files         129      129              
  Lines       18593    18604      +11     
  Branches     3225     3228       +3     
==========================================
+ Hits        17205    17215      +10     
- Misses        942      943       +1     
  Partials      446      446              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -146,6 +146,10 @@ def parse_HexBytes(self):
def _make_bytelike(cls, context, typeclass, bytez):
bytez_length = len(bytez)
btype = typeclass(bytez_length)

if bytez_length == 0:
return IRnode.from_list("~empty", typ=btype, annotation=f"empty {btype}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

i will just add context for future me.. we added this if statement to make some fast-path-out optimizations easier to detect. e.g. in make_bytearray_coppier we now directly store to destination if we detect empty without having to load anything

Copy link
Collaborator

@cyberthirst cyberthirst left a comment

Choose a reason for hiding this comment

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

let's just merge charles-cooper#86 and we should be good to go

@charles-cooper charles-cooper marked this pull request as ready for review May 19, 2025 10:19
@charles-cooper charles-cooper enabled auto-merge (squash) May 19, 2025 10:27
@charles-cooper charles-cooper merged commit a06f7df into vyperlang:master May 19, 2025
159 checks passed
@charles-cooper charles-cooper deleted the fix/copy-bytes-zero-length branch May 19, 2025 11:56
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.

2 participants