Skip to content
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

Don't write files during multipart processing in TinyGo #399

Merged
merged 6 commits into from
Sep 13, 2022

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Sep 6, 2022

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2022

Codecov Report

Base: 77.13% // Head: 77.12% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (643b792) compared to base (3dee5e2).
Patch coverage: 57.14% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           v3/dev     #399      +/-   ##
==========================================
- Coverage   77.13%   77.12%   -0.02%     
==========================================
  Files         137      137              
  Lines        5975     5985      +10     
==========================================
+ Hits         4609     4616       +7     
- Misses       1100     1102       +2     
- Partials      266      267       +1     
Flag Coverage Δ
no-tinygo 77.19% <42.85%> (-0.07%) ⬇️
overall 77.12% <57.14%> (-0.02%) ⬇️
tinygo 75.47% <28.57%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
bodyprocessors/multipart.go 68.49% <57.14%> (+0.23%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@anuraaga anuraaga marked this pull request as draft September 6, 2022 03:20
@anuraaga
Copy link
Contributor Author

anuraaga commented Sep 6, 2022

Actually will investigate some more, one test passes and the next crashes, will see what's going on

@anuraaga anuraaga marked this pull request as ready for review September 6, 2022 04:05
transaction.go Outdated
for _, name := range tx.Variables.Files.Get("") {
// TODO we kind of assume file_size is always populated with the name at index 0.
// Instead perhaps we need to have a collection of structs rather than multiple collections.
size, _ := strconv.ParseInt(tx.Variables.FilesSizes.Get(name)[0], 10, 64)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found this bug when running ftw with wasm, after fixing the above :)

if err != nil {
return err
var size int64
if !environment.IsTinyGo {
Copy link
Member

Choose a reason for hiding this comment

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

nit: can you do first the negative to save one negation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry JC I missed this comment - I can followup with the change if you feel strongly about it. I've generally wanted to keep "normal code" first, and TinyGo code later in order where possible

@jcchavezs
Copy link
Member

Curious about this change, I was wondering if os inclusion would get the filesystem error in WASM.

@jptosso
Copy link
Member

jptosso commented Sep 6, 2022

I think the multipart processor should be optimized. Keep in mind that the size of the reader is not greater than the request body memory limit (about 100kb)

Maybe in the case of tinygo we should handle the body in memory? rather than discarding it?

@jcchavezs
Copy link
Member

Maybe in the case of tinygo we should handle the body in memory? rather than discarding it?

Since it is single thread and the body has a limit we could handle it in memory, what do you think @anuraaga?

@anuraaga
Copy link
Contributor Author

anuraaga commented Sep 7, 2022

The code works fine in wasm, envoy stubs out a subset of fs APIs and this seems to only hit those.

Yeah I thought of handling in-memory for wasm case, but it looked like it would take some reasonable work. Can we do it in a separate PR to first fix failure on just filename rules that happens right now?

@jcchavezs
Copy link
Member

Yeah I think it makes sense to do in a separate PR to keep the scope small.

@anuraaga anuraaga merged commit 0ffb09a into corazawaf:v3/dev Sep 13, 2022
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.

None yet

4 participants