build(vorbis): update libvorbis past its negative left shift in the psychoacoustic setup #11480

Merged
MarcZX10 merged 1 commit from upstream-pr/11480 into main 2026-10-27 08:26:42 +00:00
MarcZX10 commented 2026-10-26 16:35:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T16:35:57Z.


What

The bundled libvorbis (3rdparty/vorbis at 0657aee6) builds its bark table in _vp_psy_init with p->bark[i]=((lo-1)<<16)+(hi-1); (lib/psy.c:319). For the first bands lo is 0, so it left-shifts a negative value, which is undefined behaviour. With -fsanitize=undefined and halt_on_error, guest_vorbis_dec stops there: psy.c:319:23: runtime error: left shift of negative value -4.

Upstream fixed it in c2aa86b0 ("Replaced left shift of negative number with multiplication"), which writes ((lo-1)*(1<<16))+(hi-1), the same value without the shift. This moves the submodule to that commit instead of patching the file locally. Between the two commits, the library sources change only in four files, all fixes or const qualifiers:

  • psy.c: this fix, plus the half-octave bounds check in _vp_psy_init (315da9cc).
  • sharedbook.c: a cast to unsigned to avoid another undefined shift (bb4047de).
  • smallft.c: constants marked const.
  • vorbisfile.c: a misleading-indentation fix.

The rest are upstream CMake, CI, test and documentation changes; libSceVorbisDec builds the library from its own source list, so they do not affect this build.

Tested

On an ubuntu-latest fork runner:

  • RelWithDebInfo build: guest_vorbis_dec and guest_ajm_wvorbis pass.
  • -DANYPS5_ENABLE_ASAN=ON with -fsanitize=undefined -fno-sanitize=vptr and UBSAN_OPTIONS=halt_on_error=1: both pass. With the submodule checked out back at 0657aee6 in the same build, guest_vorbis_dec fails with psy.c:319:23: runtime error: left shift of negative value -4.

python3 tools/check_conventions.py --base upstream/main passes and tools/pr_overlap.py --branch reports no overlap with open pull requests. Windows and macOS were not run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (the existing libvorbis submodule moves to a newer upstream commit)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5021075248 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11480). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T16:35:57Z. --- ### What The bundled libvorbis (`3rdparty/vorbis` at `0657aee6`) builds its bark table in `_vp_psy_init` with `p->bark[i]=((lo-1)<<16)+(hi-1);` (`lib/psy.c:319`). For the first bands `lo` is 0, so it left-shifts a negative value, which is undefined behaviour. With `-fsanitize=undefined` and `halt_on_error`, `guest_vorbis_dec` stops there: `psy.c:319:23: runtime error: left shift of negative value -4`. Upstream fixed it in [`c2aa86b0`](https://github.com/xiph/vorbis/commit/c2aa86b05e981c96bf381fc6aa11cdd03eccc2fb) ("Replaced left shift of negative number with multiplication"), which writes `((lo-1)*(1<<16))+(hi-1)`, the same value without the shift. This moves the submodule to that commit instead of patching the file locally. Between the two commits, the library sources change only in four files, all fixes or `const` qualifiers: - `psy.c`: this fix, plus the half-octave bounds check in `_vp_psy_init` (`315da9cc`). - `sharedbook.c`: a cast to unsigned to avoid another undefined shift (`bb4047de`). - `smallft.c`: constants marked `const`. - `vorbisfile.c`: a misleading-indentation fix. The rest are upstream CMake, CI, test and documentation changes; `libSceVorbisDec` builds the library from its own source list, so they do not affect this build. ### Tested On an `ubuntu-latest` fork runner: - RelWithDebInfo build: `guest_vorbis_dec` and `guest_ajm_wvorbis` pass. - `-DANYPS5_ENABLE_ASAN=ON` with `-fsanitize=undefined -fno-sanitize=vptr` and `UBSAN_OPTIONS=halt_on_error=1`: both pass. With the submodule checked out back at `0657aee6` in the same build, `guest_vorbis_dec` fails with `psy.c:319:23: runtime error: left shift of negative value -4`. `python3 tools/check_conventions.py --base upstream/main` passes and `tools/pr_overlap.py --branch` reports no overlap with open pull requests. Windows and macOS were not run. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source (the existing libvorbis submodule moves to a newer upstream commit) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11480
No description provided.