A 44-Item Audit: Bridge Loops, Ring-Cache Corruption, and 5 TMDB Genre Pairs
Highlights from Batches 2-5 of Vela Player 1.3.1's deep audit (docs/deep-review-2026-11-19.md): http_bridge accept() exiting permanently on ECONNABORTED, partial pwrite corrupting readahead's ring cache, venc.c teardown UAF, bitmap_compose negative-offset UB, ftp_io strtok(), Asset Store Kit token migration, and SQLite LIKE genre cross-matching.
Before shipping Vela Player 1.3.1, I ran a full codebase audit (docs/deep-review-2026-11-19.md), logging 44 issues (DR-01 through DR-44). After resolving them, all 515 host-side JS tests and the native C suites (including ASan + UBSan runs) passed.
These are the sharpest bugs from Batches 2–5 — the kind that breeze past happy-path testing and fail silently or corrupt state on real devices.
1. http_bridge.c: one ECONNABORTED kills the stream bridge (DR-07)
The local HTTP bridge’s accept_main() loop used to check only errno == EINTR; any other accept(2) error triggered an immediate break.
When a player seeks rapidly or a TV drops a half-open handshake, accept(2) routinely returns ECONNABORTED, EAGAIN, EPROTO, or EHOSTUNREACH, and descriptor exhaustion yields EMFILE/ENFILE. Breaking out of the loop stopped the accept thread permanently without clearing g_port. Upper layers kept requesting http://127.0.0.1:<port>/... while nobody was listening anymore — requiring a full app kill to recover.
The fix extracts is_transient_accept_err() (covering HarmonyOS musl and macOS host test macros) to continue immediately, sleeps 50ms with logging on EMFILE/ENFILE/ENOMEM, and only clears g_port = -1 and closes g_listen_fd on genuinely fatal errors.
2. readahead.c: partial pwrite corruption and truncated paths (DR-09)
To avoid hitting the NAS every time a user rewinds 10 seconds, readahead.c spills evicted RAM blocks into a 256 MiB circular disk file (ra-%p.bin). The audit caught three bugs in that ring file:
- Torn blocks on partial
pwrite:disk_spill_locked()overwrote occupied slots in-place and returned early ifpwritewrote fewer bytes than requested, leavingdiskSlotBlock[slot]pointing at the old block number while disk bytes held a mix of old and new data. Rewinding into that slot played audio glitches. Nowdisk_spill_locked()invalidates slot metadata before writing, uses apwrite_full()retry loop forEINTR/short writes, and marks the slot empty on any failure. - 512-byte path truncation:
diskDirwas 512 bytes anddiskPathwas also 512 bytes. Appending/ra-0x....bintruncated long sandbox paths, breakingunlink(ra->diskPath)and leaking temp files.diskPathis now 640 bytes,mq_ra_set_disk()rejects oversized paths, andopen()addsO_NOFOLLOW | O_CLOEXEC. mq_ra_read()now rejectspos < 0, verified under ASan + UBSan viatest_disk_negative_and_long_dirintools/test-readahead.c.
3. Native engine UB and races: venc.c, bitmap_compose.c, ftp_io.c, iso_io.c
- Mutex destroyed before encoder callbacks stopped (
DR-11,entry/src/main/cpp/transcode/venc.c): OnPrepare()orStart()failure,mq_venc_open()destroyedv->condandv->lockbefore callingOH_VideoEncoder_Destroy(v->codec), creating a UAF whenevervenc_on_errorfired from the encoder thread. I reversed the teardown order, movedread_layout()beforeStart()to eliminate a race withvenc_on_stream_changed, widenedneedtoint64_t need64withstride >= width && sliceH >= heightguards, and switchedv->condfromCLOCK_REALTIMEtoCLOCK_MONOTONIC. - Negative-offset pointer UB (
DR-12,entry/src/main/cpp/subtitle/bitmap_compose.c): Whenrect->x < 0, the inner loop computedrgba + ((size_t)dy * w + ox) * 4before checking0 <= dx && dx < w, wrappingoxinto a huge unsigned offset, and cast potentially negativelinesize[0]values tosize_t. Bounds checks now precede pointer arithmetic, stride usesptrdiff_t, and bounding boxes useint64_t. - Non-threadsafe
strtok()(DR-13,ftp_io.c) and off-by-one VOB skip (DR-14,iso_io.c):ftp_parse_mlsd_line()called globalstrtok()during concurrent directory scans (switched tostrtok_r), andftpio_pread()left a broken data socket open on read errors (ftpio_drop_data(s); s->pos = -1;fixes it). Meanwhile,iso_io.c’smerge_vobs()checkede->name[8] == '0'— index 8 inVTS_01_0.VOBis., so DVD menus were never skipped until fixed toname[7] != '0'.
4. Credential leakage and a skipped SQLite migration (DR-05, DR-23)
Vela’s privacy policy promises all tokens live in HarmonyOS Asset Store Kit rather than plaintext files. Yet TraktClient stored trakt_token/trakt_refresh and OpenSubtitlesClient stored os_token in plaintext marquee_prefs. Both now migrate on first read into SecretVault.putNamed()/getNamed() with a CLEARED_KEY flag to prevent stale values returning if the vault is unavailable (DR-05).
Worse, Db.ets had placed the 1.3.0 progress.subtitlePath credential-scrubbing logic inside if (store.version < 2), meaning every user upgrading from database versions v2 through v9 skipped it silently (DR-23). Moving it into an independent migrateProgressSubtitles() under store.version < 10 fixed the gap.
5. SQLite LIKE wildcards across 5 TMDB genre pairs, plus SafeArea.reset() (DR-25, DR-35)
When testing 1.2.0’s genre filter, selecting “Action” (动作) pulled in “Action & Adventure” (动作冒险). Across five TMDB genre pairs — 动作/冒险/科幻/奇幻/战争 colliding with compound labels like 动作冒险, 科幻奇幻, and 战争政治 — genres LIKE '%xxx%' cross-matched and inflated facet counts, while typing % or _ in search matched the whole database.
LibrarySql.ets now provides escapeLike() (escaping !, %, _ with ESCAPE '!'), and Stores.ets wraps genres in commas (',' || genres || ',' LIKE '%,动作,%') for exact token matching in both filtered() and selectionFacets().
Finally, DR-35 caught a lifecycle lockup in SafeArea.ets: EntryAbility.onWindowStageDestroy() never cleared SafeArea.win or unregistered listeners. If HarmonyOS destroyed and recreated the WindowStage in the same process, SafeArea.ensure() saw win !== null and returned early, freezing status-bar and 28vp bottom-bar insets on stale numbers. Adding SafeArea.reset() in onWindowStageDestroy() cleared it cleanly.
Comments