[{"data":1,"prerenderedAt":13,"buildId":14},["ShallowReactive",2],{"$fha878zj0w6re":3},{"rec_no":4,"title":5,"category":6,"dist":7,"update":10,"contents":11,"description":12},190,"bluetoothdがUTF-8のエラーで落ちる（BlueZ 5.82、Raspberry Pi OS trixie）","raspi",[8,9],"RaspberryPi Zero 2 W","Raspberry Pi OS 13 (trixie)","2026-12-01","対象：Raspberry Pi OS（Debian 13 trixie）、BlueZ 5.82-1.1+rpt2\u003Cbr>\n\u003Cbr>\n\u003Cp>Apple TV から Bluetooth で音を受けていたところ、YouTube の特定の動画で音が止まり、Bluetooth の接続が切れたままになりました。原因と、BlueZ に修正を当ててビルドし直した手順です。\u003Cbr>\n\u003Cbr>\n\u003Cb>症状\u003C\u002Fb>\u003Cbr>\nbluetoothd が強制終了していました。\u003Cbr>\n$\u003Cspan class='text-color'>journalctl -u bluetooth --no-pager | tail\u003C\u002Fspan>\u003Cbr>\n\u003Cdiv style=\"background-color:silver\">\n\u003Cspan>arguments to dbus_message_iter_append_basic() were incorrect, assertion \"_dbus_check_is_valid_utf8 (*string_p)\" failed\u003C\u002Fspan>\u003Cbr>\n\u003Cspan>bluetooth.service: Main process exited, code=killed, status=6\u002FABRT\u003C\u002Fspan>\u003Cbr>\n\u003C\u002Fdiv>\nsystemd が bluetoothd を自動で起動し直しますが、Apple TV との接続は切れたままになります。\u003Cbr>\n\u003Cbr>\n\u003Cb>原因\u003C\u002Fb>\u003Cbr>\nApple TV は AVRCP で再生中の動画のタイトルなど（メタデータ）を送ってきます。この中に正しくない UTF-8 が含まれていると、bluetoothd がそのまま D-Bus に渡し、libdbus のチェックで強制終了します。\u003Cbr>\n\u003Cbr>\nBlueZ 本家では「audio\u002Fplayer: Ensure metadata string is valid UTF-8」（コミット fb0f8f49、2026年4月）で修正されていて、5.87 から入っています。trixie の BlueZ は 5.82 のままでした（2026年11月時点）。\u003Cbr>\n5.82 には本家の修正が使っている関数（strtoutf8）がないため、GLib の g_utf8_validate() と g_utf8_make_valid() で同じことをする修正を当てました。正しくない部分を U+FFFD（�）に置き換え、正しい文字列はそのままにします。\u003Cbr>\n\u003Cbr>\n\u003Cb>注意：ソースは Raspberry Pi 版を使う\u003C\u002Fb>\u003Cbr>\nRaspberry Pi OS の bluez は、Raspberry Pi 独自の版（5.82-1.1+rpt2、archive.raspberrypi.com）です。Debian 本家のソースでビルドすると Raspberry Pi 独自の変更が抜けるので、インストールされている版を確認して、その版のソースを取得します。\u003Cbr>\n$\u003Cspan class='text-color'>apt-cache policy bluez\u003C\u002Fspan>　　（Installed の版を確認）\u003Cbr>\n\u003Cbr>\n\u003Cb>1. ソースを取得できるようにする\u003C\u002Fb>\u003Cbr>\nRaspberry Pi のリポジトリ（raspi.sources）にも deb-src を追加します。\u003Cbr>\n$\u003Cspan class='text-color'>sudo cp \u002Fetc\u002Fapt\u002Fsources.list.d\u002Fraspi.sources \u002Fetc\u002Fapt\u002Fsources.list.d\u002Fraspi.sources.bak\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>sudo sed -i 's\u002F^Types: deb$\u002FTypes: deb deb-src\u002F' \u002Fetc\u002Fapt\u002Fsources.list.d\u002Fraspi.sources\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>sudo apt update\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>sudo apt install -y build-essential devscripts tmux\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>sudo apt build-dep -y bluez\u003C\u002Fspan>\u003Cbr>\n\u003Cbr>\n\u003Cb>2. ソースの取得と修正\u003C\u002Fb>\u003Cbr>\n$\u003Cspan class='text-color'>mkdir -p ~\u002Fbuild && cd ~\u002Fbuild\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>apt source bluez=5.82-1.1+rpt2\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>cd bluez-5.82\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>head -3 debian\u002Fchangelog\u003C\u002Fspan>　　（+rpt2 になっていること）\u003Cbr>\n\u003Cbr>\n次の内容を ~\u002Fbuild\u002Fbluez-utf8.patch として保存します。\u003Cbr>\n\u003Cpre style=\"background-color:silver\">\n--- a\u002Fprofiles\u002Faudio\u002Fplayer.c\n+++ b\u002Fprofiles\u002Faudio\u002Fplayer.c\n@@ -1441,6 +1441,13 @@\n \tGHashTable *metadata = item ? item->metadata : mp->track;\n \n \tvalue = g_strndup(data, len);\n+\n+\t\u002F* D-Bus requires valid UTF-8 (same idea as upstream fb0f8f49) *\u002F\n+\tif (!g_utf8_validate(value, -1, NULL)) {\n+\t\tchar *valid = g_utf8_make_valid(value, -1);\n+\t\tg_free(value);\n+\t\tvalue = valid;\n+\t}\n \n \tDBG(\"%s: %s\", key, value);\n \n\u003C\u002Fpre>\n$\u003Cspan class='text-color'>patch -p1 -l --dry-run &lt; ~\u002Fbuild\u002Fbluez-utf8.patch\u003C\u002Fspan>　　（エラーが出なければ）\u003Cbr>\n$\u003Cspan class='text-color'>patch -p1 -l &lt; ~\u002Fbuild\u002Fbluez-utf8.patch\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>dch --local +utf8 \"Validate UTF-8 of AVRCP metadata before D-Bus\"\u003C\u002Fspan>　　（版を 5.82-1.1+rpt2+utf81 にする）\u003Cbr>\n\u003Cbr>\n\u003Cb>3. ビルド\u003C\u002Fb>\u003Cbr>\nZero 2 W で約1時間かかるので、tmux の中で実行します（tmux は単独で起動してから、次のコマンドを打ちます）。\u003Cbr>\n$\u003Cspan class='text-color'>tmux\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -us -uc -b\u003C\u002Fspan>\u003Cbr>\n\u003Cbr>\n\u003Cb>4. インストール\u003C\u002Fb>\u003Cbr>\n入っている3つのパッケージだけを入れ替えて、apt upgrade で元の版に戻らないよう固定します。インストールだけでは bluetoothd が再起動されなかったので、手で再起動します。\u003Cbr>\n$\u003Cspan class='text-color'>cd ~\u002Fbuild\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>sudo apt install -y .\u002Fbluez_5.82-1.1+rpt2+utf81_arm64.deb .\u002Flibbluetooth3_5.82-1.1+rpt2+utf81_arm64.deb .\u002Flibbluetooth-dev_5.82-1.1+rpt2+utf81_arm64.deb\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>sudo apt-mark hold bluez libbluetooth3 libbluetooth-dev\u003C\u002Fspan>\u003Cbr>\n$\u003Cspan class='text-color'>sudo systemctl restart bluetooth\u003C\u002Fspan>\u003Cbr>\n\u003Cbr>\n\u003Cb>5. 確認\u003C\u002Fb>\u003Cbr>\n$\u003Cspan class='text-color'>dpkg -l | grep -E \"^.i +(bluez|libbluetooth)\" | awk '{print $1, $2, $3}'\u003C\u002Fspan>　　（hold 中は状態が hi）\u003Cbr>\n$\u003Cspan class='text-color'>journalctl -u bluetooth --since \"10 min ago\" --no-pager | grep -E \"utf8|ABRT|exited\"\u003C\u002Fspan>　　（何も出なければよい）\u003Cbr>\n\u003Cbr>\n修正後は、止まっていた動画でも止まらず、ABRT も出なくなりました。\u003Cbr>\n\u003Cbr>\n\u003Cb>修正入りの版が出たら\u003C\u002Fb>\u003Cbr>\nhold しているので、bluez は apt upgrade で更新されません。セキュリティ修正などで新しい版が出たら、新しい版のソースで同じ手順をやり直します。本家の修正入り（5.87 以降）が trixie に来たら、hold を外して apt の版に戻せます。\u003Cbr>\n$\u003Cspan class='text-color'>sudo apt update && apt-cache policy bluez\u003C\u002Fspan>　　（新しい版が出たか）\u003Cbr>\n$\u003Cspan class='text-color'>grep -n -A8 \"media_player_set_metadata(\" bluez-*\u002Fprofiles\u002Faudio\u002Fplayer.c | grep -E \"strtoutf8|utf8\"\u003C\u002Fspan>　　（新しいソースに修正が入っているか）\u003Cbr>\n$\u003Cspan class='text-color'>sudo apt-mark unhold bluez libbluetooth3 libbluetooth-dev\u003C\u002Fspan>　　（修正入りなら hold を外して apt install）\u003Cbr>\n\u003Cbr>\n※ 以前は AVRCP を無効にしてクラッシュを避けていましたが、原因が分かったので、AVRCP は有効のまま使っています（Apple TV の音量の連動に使います）。\u003Cbr>\n\u003C\u002Fp>\n","対象：Raspberry Pi OS（Debian 13 trixie）、BlueZ 5.82-1.1+rpt2 Apple TV から Bluetooth で音を受けていたところ、YouTube の特定の動画で音が止まり、Bluetoot…",1796091242169,"eb55065c-e717-4894-b4db-112ac4ae48bd"]