Skip to content

Utilize C99 flexible array members to allow for FORTIFY/ASAN#4944

Open
satur9nine wants to merge 1 commit into
bytecodealliance:mainfrom
satur9nine:c99-fam
Open

Utilize C99 flexible array members to allow for FORTIFY/ASAN#4944
satur9nine wants to merge 1 commit into
bytecodealliance:mainfrom
satur9nine:c99-fam

Conversation

@satur9nine
Copy link
Copy Markdown

When building the code today with:

-fsanitize=bounds,bounds-strict,vla-bound 
-fsanitize-trap=bounds,bounds-strict,vla-bound 

WAMR crashes in various places when trying to use arrays of length one as if they are flexible array members. This change enables use of real C99+ flexible array members when the compiler supports it.

Copy link
Copy Markdown
Contributor

@lum1n0us lum1n0us left a comment

Choose a reason for hiding this comment

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

Please ignore the SGX CI failure for now and focus on investigating the Ubuntu-side issue. Once that is fixed, this should be ready to merge.


I agree that the issue addressed here is real: using trailing [1] / [0] arrays as flexible array members is not the C99-standard form, and stricter bounds/FORTIFY-style checking can legitimately diagnose or trap on such patterns.

My guess is that some of these non-standard forms were originally kept for compiler compatibility, especially when the same headers may be consumed by C++ compilers. That said, in the codebase there also appear to be two different cases mixed together: some are true variable-length tail storage and should be normalized toward standard FAM usage where possible, while others are effectively just placeholders for layout/type-compatibility purposes and would be better expressed with a clearer non-array representation rather than continuing to look like tail arrays.

With that in mind, this PR looks more like a partial fix than a complete cleanup. It resolves some real problematic cases, but there are still a non-trivial number of similar definitions remaining under core/iwasm and core/shared that have not been corrected yet. I think it would help to frame this change explicitly as an incremental step, and track the remaining cases separately so we do not give the impression that the broader issue has been fully addressed.

- Fix array.new init allocation for flexible array members
- Also minor CI fix
@satur9nine
Copy link
Copy Markdown
Author

OK found one more small thing to fix and minor CI improvement; now CI is green.

@satur9nine satur9nine requested a review from lum1n0us May 19, 2026 22:03
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