Repository navigation
Description
Summary
On Android, creating a task with a relative asset path (BaseOptions.setModelAssetPath("face_landmarker.task")) rewrites the cached copy of the model at <cacheDir>/drishti_asset_cache/face_landmarker.task every time, truncating it first. Every live task instance has that same file mmaped with MAP_SHARED, and TFLite reads constant tensors from the mapping on every Invoke. So if a second task is created while a first one is running inference, the first one can read pages beyond the (temporarily truncated) end of file and crash with SIGBUS (BUS_ADRERR).
Environment
com.google.mediapipe:tasks-vision:1.0.0/tasks-core:1.0.0(libmediapipe_tasks_jni.so, BuildId773ea834cf94bf838f4c7c9d0405590f)- Pixel 6, Android 16 (CP1A.260405.005), arm64-v8a, release build
- Face Landmarker, CPU delegate. Seen in LIVE_STREAM mode; the same overlap exists in VIDEO mode
Steps to reproduce
- Create Face Landmarker A with
setModelAssetPath("face_landmarker.task")and keep running inference on camera frames. - While A is still running inference, create Face Landmarker B with the same asset path (in our app: when the user changes
numFaces, we create a new instance and close the old one once its in-flight inference finishes). - Occasionally (about 1 in 15 re-creations for us), A's inference thread crashes.
Crash
F/libc: Fatal signal 7 (SIGBUS), code 2 (BUS_ADRERR), fault addr 0x7a0b463990 in tid 28865 (Thread-27)
signal 7 (SIGBUS), code 2 (BUS_ADRERR), fault addr 0x0000007a0b463990 (read)
memory near x23 (/data/data/<package>/cache/drishti_asset_cache/face_landmarker.task):
All 12 app frames are in libmediapipe_tasks_jni.so (no symbols). Matching each frame's function against the assert / source-file strings it references gives:
ThreadPool worker → SchedulerQueue::RunNextTask → CalculatorNode::ProcessNode → InferenceCalculator → inference_interpreter_delegate_runner.cc → tflite::Interpreter::Invoke → Subgraph::Invoke → StridedSlice Eval, which faults while reading its constant begin tensor. The fault address is inside the mapping of the cached model file. When debuggerd dumped memory ~0.7 s later the same address was readable again, because the rewrite had finished by then.
Cause
ExternalFileHandler::MapExternalFileresolvesfile_nameviaPathToResourceAsFile.- On Android,
PathToResourceAsFilesends relative paths toAssetManager::CachedFileFromAsset(mediapipe/util/resource_util_android.cc). CachedFileFromAssetwrites the asset withstd::ofstream output_file(file_path);, which truncates the file and then writes it. The comment says it overwrites the cache file unconditionally (mediapipe/util/android/asset_manager_util.cc).ExternalFileHandlerthenopen(O_RDONLY)+mmap(PROT_READ, MAP_SHARED)s that file. The.taskentries are stored uncompressed, so TFLite uses the model in place and constant tensors point into the mapping.- Each
TaskRunnerhas its ownModelResourcesCache, so every new task repeats steps 1–4 on the same path while older tasks are still reading their mapping. Truncating a file removes its pages from every mapping, and a read past the current EOF raisesSIGBUS.
Suggested fix
Write the cache file to a temporary file in the same directory and rename() it over the destination. Existing mappings keep the old inode, so nobody reads a truncated file. Alternatively, skip the rewrite when the cached file already has the same size and contents.
Workaround
Load the asset once into a direct ByteBuffer and pass it with BaseOptions.setModelAssetBuffer(...), keeping the buffer alive for the life of the process. MediaPipe then passes the pointer through FilePointerMeta and never touches the cache file. This fixed the crash for us.
Possibly related
#1817 (SIGBUS BUS_ADRERR on startup with two graphs, closed without a root cause) may have the same cause: two graphs starting at the same time, each rewriting the cached assets while the other is reading them.
Activity
HarishPermal commentedon Sep 28, 2026
hi @Wancky
Thanks for raising this issue, and also the suggested fix im currently testing it and soon will update with the status here