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

UTF8ToString fails on specific strings #14786

Closed
jeffRTC opened this issue Aug 1, 2021 · 3 comments
Closed

UTF8ToString fails on specific strings #14786

jeffRTC opened this issue Aug 1, 2021 · 3 comments

Comments

@jeffRTC
Copy link

jeffRTC commented Aug 1, 2021

@sbc100 @kripken

This is a crazy one.

I pass Base64 strings like eyJuYW1lIjogIkphc29uIiwgImFnZSI6ICI0OCJ9 to JavaScript side.

Basically,

std::string text = "eyJuYW1lIjogIkphc29uIiwgImFnZSI6ICI0OCJ9";

// Call C-extern function
printSomething(text.c_str());

Now Javascript side try convert the pointer passed to JS function to UTF8 string using this way,

    printSomething: async function(pText) {
        let converted = UTF8ToString(pText);
        
        console.log(converted)
    }

But it returns an empty string as a result instead eyJuYW1lIjogIkphc29uIiwgImFnZSI6ICI0OCJ9.

I've ran the Javascript debugger over UTF8ToString and I find that it returns "\u0001" so for naked eye it's an empty string..

@jeffRTC
Copy link
Author

jeffRTC commented Aug 1, 2021

I've ran dozens of texts to make sure this issue is not on my side. This doesn't happen with simple strings according to my tests.

"Hello World" 
"FooBar"
"Dan Rocks"
"www.google.com"

All got printed..

I'm using following flags when compiling

-Wall -Wextra -g2 -s ASSERTIONS=2 -s INITIAL_MEMORY=500MB -s ALLOW_MEMORY_GROWTH=1 
-fsanitize=address -fsanitize=undefined -s DEMANGLE_SUPPORT=1 -gseparate-dwarf 
-s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_TABLE_GROWTH=1 -std=gnu++17

Ubsan and Address Sanitizer is enabled and It didn't caught anything like heap after use etc

@jeffRTC
Copy link
Author

jeffRTC commented Aug 1, 2021

Turns out, I'm using an invalidated pointer but for some reason the small strings got lucky. Fixed it by using a local copy inside class...

@jeffRTC jeffRTC closed this as completed Aug 1, 2021
@sbc100
Copy link
Collaborator

sbc100 commented Aug 2, 2021

Do async functions work at all in library JS files? What does that mean in that context?

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

No branches or pull requests

2 participants