Skip to content

Fix panic when size 0 passed to malloc #3303

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
merged 1 commit into from
Nov 21, 2022

Conversation

anuraaga
Copy link
Contributor

Currently it will panic (I think Go may translate &buf[0] without a length check)

https://linux.die.net/man/3/realloc

  • malloc/calloc can return NULL for empty size
  • realloc with empty is equivalent to free

Copy link
Member

@dgryski dgryski left a comment

Choose a reason for hiding this comment

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

LGTM.

@deadprogram
Copy link
Member

Thank you for the fixes @anuraaga and thanks for reviewing @dgryski

Also, thanks for the helpful link @anuraaga

Now merging.

@deadprogram deadprogram merged commit b731919 into tinygo-org:dev Nov 21, 2022
lann added a commit to lann/tinygo that referenced this pull request Jan 24, 2023
PR tinygo-org#3303 addressed panics when malloc'ing with size 0 by returning nil.
While this is permitted by the C standard, some wasm environments expect
the behavior to match that of glibc/dlmalloc, which is to always return
a unique pointer.
Mossaka added a commit to Mossaka/wit-bindgen that referenced this pull request Jan 31, 2023
The issue with "fragment is larger than or outside of variable" is
a known issue and has been resolved in tinygo v0.26.

However, tinygo v0.26 introduces a regression for wasm/wasi target
where the compiler panics when size 0 passed to malloc. See
tinygo-org/tinygo#3303 for details

Signed-off-by: Jiaxiao Zhou <[email protected]>
@anuraaga anuraaga mentioned this pull request Feb 3, 2023
alexcrichton pushed a commit to bytecodealliance/wit-bindgen that referenced this pull request Feb 16, 2023
* created wit-bindgen-gen-guest-go crate and added to the clap CLI

Signed-off-by: Jiaxiao Zhou <[email protected]>

* rewrote import and export using a more generic conversion method

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: records working

Signed-off-by: Jiaxiao Zhou <[email protected]>

* simply code

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: tuple works

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: list works

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: string works

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: option works

Signed-off-by: Jiaxiao Zhou <[email protected]>

* implemented result type

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: result works

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: result option work

Signed-off-by: Jiaxiao Zhou <[email protected]>

* added codegen for go bindgen. Further work needs to pass all the tests

Signed-off-by: Jiaxiao Zhou <[email protected]>

* get more tests passed, including conventions

Signed-off-by: Jiaxiao Zhou <[email protected]>

* now flags and alias are working

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: implemented multi-return

Signed-off-by: Jiaxiao Zhou <[email protected]>

cargo clippy

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: implemented union, enum and variantss

Signed-off-by: Jiaxiao Zhou <[email protected]>

* rewrite lower's Result for imports

* avoid Go keywords conflict with wit's variable names

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: all codegen tests passed.

The issue with "fragment is larger than or outside of variable" is
a known issue and has been resolved in tinygo v0.26.

However, tinygo v0.26 introduces a regression for wasm/wasi target
where the compiler panics when size 0 passed to malloc. See
tinygo-org/tinygo#3303 for details

Signed-off-by: Jiaxiao Zhou <[email protected]>

* refactor: add gen-guest-c dependency to gen-guest-go.

Signed-off-by: Jiaxiao Zhou <[email protected]>

* cargo lock file

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: passed new tests associated cross-interface feature

Signed-off-by: Jiaxiao Zhou <[email protected]>

* formatted code

Signed-off-by: Jiaxiao Zhou <[email protected]>

* gh action: installed tinygo

Signed-off-by: Jiaxiao Zhou <[email protected]>

* install go 1.19

Signed-off-by: Jiaxiao Zhou <[email protected]>

* generate C files together with Go files

Signed-off-by: Jiaxiao Zhou <[email protected]>

* added option-result test

Signed-off-by: Jiaxiao Zhou <[email protected]>

* fix a typo in wit-bindgen-cli doc

Signed-off-by: Jiaxiao Zhou <[email protected]>

* updated README to include gen-guest-go

Signed-off-by: Jiaxiao Zhou <[email protected]>

* removed option-result.wit

Signed-off-by: Jiaxiao Zhou <[email protected]>

* fix the broken CLI

Signed-off-by: Jiaxiao Zhou <[email protected]>

* added go to runtime test

Signed-off-by: Jiaxiao Zhou <[email protected]>

* free C parameters and variables

Signed-off-by: Jiaxiao Zhou <[email protected]>

* removed memory free for return variables in export and invoke arguments in import

Signed-off-by: Jiaxiao Zhou <[email protected]>

* implemented lists

Signed-off-by: Jiaxiao Zhou <[email protected]>

* fixed a small bug around lowering nested option types

Signed-off-by: Jiaxiao Zhou <[email protected]>

* improve readability of code

Signed-off-by: Jiaxiao Zhou <[email protected]>

* changed the variant's package name to the world's name.

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: re-implement results

Signed-off-by: Jiaxiao Zhou <[email protected]>

* Fixed a small reference issue for lowering result

* re-implement variants and unions

Signed-off-by: Jiaxiao Zhou <[email protected]>

* fixed a few small bugs around variants and union types. Added variant runtime tests

Signed-off-by: Jiaxiao Zhou <[email protected]>

* turn off gc-leaking in tinygo 0.26

Signed-off-by: Jiaxiao Zhou <[email protected]>

* simplify code and add multi-return to lowering

* Added runtime tests for list, number and variant

* Added flavorful runtime test

* Added tests for many_aguments, records and smoke

* Added strings and unions runtime tests

* removed http from runtime test

Signed-off-by: Jiaxiao Zhou <[email protected]>

* added go bindgen build step to ci

* updated tinygo to 0.27. All tests should pass now

Signed-off-by: Jiaxiao Zhou <[email protected]>

* fixed go version to 1.20 instead of 1.2

Signed-off-by: Jiaxiao Zhou <[email protected]>

* disable string test because unicode hasn't been handled properly

Signed-off-by: Jiaxiao Zhou <[email protected]>

* deleted wasm abi flag

* merged main

Signed-off-by: Jiaxiao Zhou <[email protected]>

* Move go's files to it's own subfolder

* move C gen files to its own folder

Signed-off-by: Jiaxiao Zhou <[email protected]>

* update go from 1.19 to 1.20

Signed-off-by: Jiaxiao Zhou <[email protected]>

* changed tinygo crate version to 0.1.0

Signed-off-by: Jiaxiao Zhou <[email protected]>

* diable variants test for go

Signed-off-by: Jiaxiao Zhou <[email protected]>

* Fixed a missing argument to encode

* Fix referring to foreign imported paths in go

Signed-off-by: Jiaxiao Zhou <[email protected]>

* disable lift-foreign tests for now

Signed-off-by: Jiaxiao Zhou <[email protected]>

* run rustfmt

Signed-off-by: Jiaxiao Zhou <[email protected]>

---------

Signed-off-by: Jiaxiao Zhou <[email protected]>
rvolosatovs pushed a commit to bytecodealliance/wrpc that referenced this pull request May 23, 2024
* created wit-bindgen-gen-guest-go crate and added to the clap CLI

Signed-off-by: Jiaxiao Zhou <[email protected]>

* rewrote import and export using a more generic conversion method

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: records working

Signed-off-by: Jiaxiao Zhou <[email protected]>

* simply code

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: tuple works

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: list works

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: string works

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: option works

Signed-off-by: Jiaxiao Zhou <[email protected]>

* implemented result type

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: result works

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: result option work

Signed-off-by: Jiaxiao Zhou <[email protected]>

* added codegen for go bindgen. Further work needs to pass all the tests

Signed-off-by: Jiaxiao Zhou <[email protected]>

* get more tests passed, including conventions

Signed-off-by: Jiaxiao Zhou <[email protected]>

* now flags and alias are working

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: implemented multi-return

Signed-off-by: Jiaxiao Zhou <[email protected]>

cargo clippy

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: implemented union, enum and variantss

Signed-off-by: Jiaxiao Zhou <[email protected]>

* rewrite lower's Result for imports

* avoid Go keywords conflict with wit's variable names

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: all codegen tests passed.

The issue with "fragment is larger than or outside of variable" is
a known issue and has been resolved in tinygo v0.26.

However, tinygo v0.26 introduces a regression for wasm/wasi target
where the compiler panics when size 0 passed to malloc. See
tinygo-org/tinygo#3303 for details

Signed-off-by: Jiaxiao Zhou <[email protected]>

* refactor: add gen-guest-c dependency to gen-guest-go.

Signed-off-by: Jiaxiao Zhou <[email protected]>

* cargo lock file

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: passed new tests associated cross-interface feature

Signed-off-by: Jiaxiao Zhou <[email protected]>

* formatted code

Signed-off-by: Jiaxiao Zhou <[email protected]>

* gh action: installed tinygo

Signed-off-by: Jiaxiao Zhou <[email protected]>

* install go 1.19

Signed-off-by: Jiaxiao Zhou <[email protected]>

* generate C files together with Go files

Signed-off-by: Jiaxiao Zhou <[email protected]>

* added option-result test

Signed-off-by: Jiaxiao Zhou <[email protected]>

* fix a typo in wit-bindgen-cli doc

Signed-off-by: Jiaxiao Zhou <[email protected]>

* updated README to include gen-guest-go

Signed-off-by: Jiaxiao Zhou <[email protected]>

* removed option-result.wit

Signed-off-by: Jiaxiao Zhou <[email protected]>

* fix the broken CLI

Signed-off-by: Jiaxiao Zhou <[email protected]>

* added go to runtime test

Signed-off-by: Jiaxiao Zhou <[email protected]>

* free C parameters and variables

Signed-off-by: Jiaxiao Zhou <[email protected]>

* removed memory free for return variables in export and invoke arguments in import

Signed-off-by: Jiaxiao Zhou <[email protected]>

* implemented lists

Signed-off-by: Jiaxiao Zhou <[email protected]>

* fixed a small bug around lowering nested option types

Signed-off-by: Jiaxiao Zhou <[email protected]>

* improve readability of code

Signed-off-by: Jiaxiao Zhou <[email protected]>

* changed the variant's package name to the world's name.

Signed-off-by: Jiaxiao Zhou <[email protected]>

* milestone: re-implement results

Signed-off-by: Jiaxiao Zhou <[email protected]>

* Fixed a small reference issue for lowering result

* re-implement variants and unions

Signed-off-by: Jiaxiao Zhou <[email protected]>

* fixed a few small bugs around variants and union types. Added variant runtime tests

Signed-off-by: Jiaxiao Zhou <[email protected]>

* turn off gc-leaking in tinygo 0.26

Signed-off-by: Jiaxiao Zhou <[email protected]>

* simplify code and add multi-return to lowering

* Added runtime tests for list, number and variant

* Added flavorful runtime test

* Added tests for many_aguments, records and smoke

* Added strings and unions runtime tests

* removed http from runtime test

Signed-off-by: Jiaxiao Zhou <[email protected]>

* added go bindgen build step to ci

* updated tinygo to 0.27. All tests should pass now

Signed-off-by: Jiaxiao Zhou <[email protected]>

* fixed go version to 1.20 instead of 1.2

Signed-off-by: Jiaxiao Zhou <[email protected]>

* disable string test because unicode hasn't been handled properly

Signed-off-by: Jiaxiao Zhou <[email protected]>

* deleted wasm abi flag

* merged main

Signed-off-by: Jiaxiao Zhou <[email protected]>

* Move go's files to it's own subfolder

* move C gen files to its own folder

Signed-off-by: Jiaxiao Zhou <[email protected]>

* update go from 1.19 to 1.20

Signed-off-by: Jiaxiao Zhou <[email protected]>

* changed tinygo crate version to 0.1.0

Signed-off-by: Jiaxiao Zhou <[email protected]>

* diable variants test for go

Signed-off-by: Jiaxiao Zhou <[email protected]>

* Fixed a missing argument to encode

* Fix referring to foreign imported paths in go

Signed-off-by: Jiaxiao Zhou <[email protected]>

* disable lift-foreign tests for now

Signed-off-by: Jiaxiao Zhou <[email protected]>

* run rustfmt

Signed-off-by: Jiaxiao Zhou <[email protected]>

---------

Signed-off-by: Jiaxiao Zhou <[email protected]>
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