Skip to content

Conversation

pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Jul 25, 2025

I'm trying to reproduce Base64ValidationUnitTests.DecodeEmptySpan but I found something else strange in the area.

This PR adds "assert" into Base64ValidatorHelper that is making sure that Span._reference is null when Span.Lenght is 0.

This assert is broken with the call from src\mono\sample\wasm\browser\Program.cs and I'm unable to reproduce that in the actual unit test.

I suspect that the span is already corrupted in the Base64.IsValid stack frame.
I can see span.reference=0 and span.length=4, which is invalid span.

        public static bool IsValid(ReadOnlySpan<char> base64Text, out int decodedLength) =>
            Base64Helper.IsValid(default(Base64CharValidatable), base64Text, out decodedLength);

The suspect code is

(func $aot_instances_System_Buffers_Text_Base64Helper_IsValid_char_System_Buffers_Text_Base64Helper_Base64CharValidatable_System_Buffers_Text_Base64Helper_Base64CharValidatable_System_ReadOnlySpan_1_char_int_ (;11905;) (param $var0 i32) (param $var1 i32) (param $var2 i32) (param $var3 i32) (result i32)
    (local $var4 i32)
    (local $var5 i32)
    (local $var6 i32)
    (local $var7 i32)
    (local $var8 i32)
    (local $var9 i64)
    (local $var10 i32)
    (local $var11 i32)
    global.get $__stack_pointer
    i32.const 80
    i32.sub
    local.tee $var4
    global.set $__stack_pointer
    local.get $var4
    local.get $var0
    i32.store offset=79

The i32.store offset=79 overwrites first 4 bytes of the span on the shadow stack.

@pavelsavara pavelsavara self-assigned this Jul 25, 2025
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Jul 25, 2025
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 25, 2025
Copy link
Contributor

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

@pavelsavara
Copy link
Member Author

/azp list

Copy link

CI/CD Pipelines for this repository:

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant