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

Build fails with Android libc #23

Closed
Cacodemon345 opened this issue Mar 18, 2021 · 7 comments
Closed

Build fails with Android libc #23

Cacodemon345 opened this issue Mar 18, 2021 · 7 comments

Comments

@Cacodemon345
Copy link
Contributor

This is the error I get when I build ZMusic with Android NDK.

[ 76%] Building CXX object source/CMakeFiles/zmusic.dir/mididevices/music_wavewriter_mididevice.cpp.o
/home/caco345/ZMusic/source/mididevices/music_wavewriter_mididevice.cpp:155:39: error: in call to 'fwrite', size * count is too large for the given buffer
                                        if (4 == fwrite(&size, 1, 5, File))
                                                                         ^
/home/caco345/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/fortify/stdio.h:116:9: note: from 'diagnose_if' attribute on 'fwrite':
        __clang_error_if(__bos_unevaluated_lt(__bos0(buf), size * count),
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/caco345/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/cdefs.h:134:52: note: expanded from macro '__clang_error_if'
#define __clang_error_if(cond, msg) __attribute__((diagnose_if(cond, msg, "error")))
                                                   ^           ~~~~
1 error generated.
@coelckers
Copy link
Member

Where does that 5 come from?

@Cacodemon345
Copy link
Contributor Author

This seems to be a buffer overflow bug too. Needs quick fixing.

@alexey-lysiuk
Copy link
Collaborator

alexey-lysiuk commented Mar 19, 2021

Not really. The given line will write four intended bytes and one junk byte to a file. It's impossible to alter stack or heap. The most severe effect would be a crash if the next byte after size variable cannot be read.

@alexey-lysiuk
Copy link
Collaborator

Does it compile with ba9e9da?

@Cacodemon345
Copy link
Contributor Author

Yep. But I am getting this warning:

/home/caco345/ZMusic/source/zmusic/zmusic.cpp:506:2: warning: deleting pointer to incomplete type '__sFILE' may cause undefined behavior [-Wdelete-incomplete]
        delete f;
        ^      ~
/home/caco345/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdio.h:58:8: note: forward declaration of '__sFILE'
struct __sFILE;
       ^
1 warning generated.

The FILE struct is an incomplete type when building for Android Nougat and later. delete f should be changed to fclose(f).

@alexey-lysiuk
Copy link
Collaborator

Done.

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

3 participants