From c72d0fb15d3d663531483cd0bc33c3e268e00a58 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Wed, 30 Dec 2020 16:38:23 -0500 Subject: [PATCH] Build libjnigraphics, imagedecoder_fuzzer on host Bug: 142252770 Bug: 169137236 Bug: 169139756 Test: SANITIZE_HOST=address make imagedecoder_fuzzer This will allow running the fuzzer much faster in order to find bugs. It also allows running with ASAN to help find memory leaks. Some symbols (e.g. ABitmap, AAssetStreamAdaptor) rely on Android-specific features, so disable them when building on the host. This still allows using the core features of AImageDecoder. This requires a change in frameworks/native (Iefdb4132d6f10f9164be85f4dc6e11883f6fd37e). Disable detecting ODR violations when building with ASAN (which is how host builds are built). Without this change, the host detects the following: ================================================================= ==4072183==ERROR: AddressSanitizer: odr-violation (0x7fb7d52b4100): [1] size=80 'vtable for android::VectorImpl' system/core/libutils/VectorImpl.cpp [2] size=80 'vtable for android::VectorImpl' system/core/libutils/VectorImpl.cpp These globals were registered at these points: [1]: #0 0x55fefda47e0d in __asan_register_globals /out/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:360:3 #1 0x7fb7d43aa77b in asan.module_ctor (/usr/local/ssd/android/master/out/host/linux-x86/fuzz/x86_64/imagedecoder_fuzzer/../lib/libhw ui.so+0x17c677b) [2]: #0 0x55fefda47e0d in __asan_register_globals /out/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:360:3 #1 0x7fb7d52a0e6b in asan.module_ctor (/usr/local/ssd/android/master/out/host/linux-x86/fuzz/x86_64/imagedecoder_fuzzer/../lib/libutils.so+0x3de6b) ==4072183==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0 SUMMARY: AddressSanitizer: odr-violation: global 'vtable for android::VectorImpl' at system/core/libutils/VectorImpl.cpp ==4072183==ABORTING Change-Id: I0ffc4e90b4083db79fbb12012e2e1284206b43e3 --- native/graphics/jni/Android.bp | 33 ++++++++++++++++++++++------ native/graphics/jni/imagedecoder.cpp | 4 ++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/native/graphics/jni/Android.bp b/native/graphics/jni/Android.bp index 4120a73268175..b9aefdd18191b 100644 --- a/native/graphics/jni/Android.bp +++ b/native/graphics/jni/Android.bp @@ -22,22 +22,20 @@ cc_library_shared { "-Wunreachable-code", ], - // our source files - // srcs: [ - "aassetstreamadaptor.cpp", - "bitmap.cpp", "imagedecoder.cpp", ], shared_libs: [ - "libandroid", "libandroid_runtime", "libhwui", "liblog", ], - header_libs: [ "libhwui_internal_headers" ], + header_libs: [ + "libhwui_internal_headers", + "jni_headers", + ], static_libs: ["libarect"], @@ -48,7 +46,24 @@ cc_library_shared { ldflags: ["-Wl,--hash-style=both"], }, }, - version_script: "libjnigraphics.map.txt", + host_supported: true, + target: { + android: { + srcs: [ + "aassetstreamadaptor.cpp", + "bitmap.cpp", + ], + shared_libs: [ + "libandroid", + ], + version_script: "libjnigraphics.map.txt", + }, + host: { + header_libs: [ + "libnativewindow_headers", + ], + }, + }, } // The headers module is in frameworks/native/Android.bp. @@ -71,6 +86,10 @@ cc_fuzz { static_libs: ["libarect"], fuzz_config: { cc: ["scroggo@google.com"], + asan_options: [ + "detect_odr_violation=1", + ], }, corpus: ["corpus/*"], + host_supported: true, } diff --git a/native/graphics/jni/imagedecoder.cpp b/native/graphics/jni/imagedecoder.cpp index 5973790e48fdf..eab5f4143968f 100644 --- a/native/graphics/jni/imagedecoder.cpp +++ b/native/graphics/jni/imagedecoder.cpp @@ -121,8 +121,12 @@ int AImageDecoder_createFromAAsset(AAsset* asset, AImageDecoder** outDecoder) { } *outDecoder = nullptr; +#ifdef __ANDROID__ auto stream = std::make_unique(asset); return createFromStream(std::move(stream), outDecoder); +#else + return ANDROID_IMAGE_DECODER_INTERNAL_ERROR; +#endif } static bool isSeekable(int descriptor) {