Skip to content

Preserve UTF-8 paths in ELF loader strings - #24349

Merged
MikeMcQuaid merged 1 commit into
mainfrom
elf-utf8-relocation-paths
Oct 24, 2026
Merged

MikeMcQuaid merged 1 commit into
mainfrom
elf-utf8-relocation-paths

Conversation

@andrew

@andrew andrew commented Oct 24, 2026

Copy link
Copy Markdown
Member

  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Codex (GPT-6) wrote the fix and regression tests, with a red/green check of the new examples and inspection of the JSON produced by brew bottle.


Keg.elf_relocation_strings discards loader strings containing non-ASCII bytes, including valid UTF-8 paths. An existing library referenced as Cellar/foo/1.0/José/libhello.so.0 is therefore omitted from the bottle's binary relocation metadata.

Validate candidates as UTF-8 so these paths reach the existing path checks, while continuing to reject invalid byte sequences. Add coverage for non-ASCII RPATHs and interpreter paths, and extend the existing brew bottle integration example with an absolute ELF library reference.

To reproduce with the regression examples:

./bin/brew tests --only=keg_relocate/elf_checker:37,keg_relocate/elf_checker:117,dev-cmd/bottle:100

With the original filter, both loader path examples return no matches and the bottle JSON omits libexec/elf-prefix from binary_relocation_files. The new filter preserves those matches and records the ELF file.

- Validate ELF loader strings as UTF-8 before checking paths, so
  valid non-ASCII references reach bottle relocation detection.
- Keep rejecting invalid byte sequences and cover loader paths
  and the binary relocation metadata produced by `brew bottle`.
Copilot AI lite review requested due to automatic review settings October 24, 2026 15:47
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1944aeb5-343d-4116-b3de-d273a61dc0c3
Commits

Reviewing files that changed from the base of the PR and between 13bc954 and f975977.

Files selected for processing: 3
  • Library/Homebrew/keg_relocate.rb
  • Library/Homebrew/test/dev-cmd/bottle_spec.rb
  • Library/Homebrew/test/keg_relocate/elf_checker_spec.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of ELF binaries whose referenced paths contain valid non-ASCII UTF-8 characters, so these paths are retained during relocation.
    • Paths containing invalid UTF-8 remain excluded, helping prevent unsupported path data from being treated as valid. The change also covers ELF interpreter paths and dependencies referenced by shared libraries.

ELF relocation string extraction now retains printable strings with valid UTF-8 and continues to exclude invalid UTF-8 strings. Tests cover non-ASCII RPATH and interpreter paths, and ELF executable relocation in the bottle integration test.

Changes: ELF relocation string handling

Layer / File(s) Summary
UTF-8 relocation strings and validation
Library/Homebrew/keg_relocate.rb, Library/Homebrew/test/keg_relocate/elf_checker_spec.rb, Library/Homebrew/test/dev-cmd/bottle_spec.rb
Extraction retains valid UTF-8 matches with their hexadecimal offsets. Tests cover non-ASCII RPATH and interpreter paths, invalid UTF-8 exclusion, and an ELF dependency in bottle relocation.

Priority: Normal

Merge Risk: Minimal · up to f9759

No actionable merge-blocking risk is established for this change.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly summarises the main change: preserving valid UTF-8 paths in ELF loader strings.
Description check Passed The description explains the defect, the fix, the validation approach, and the added test coverage. It directly matches the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The reviewed changes address the UTF-8 path regression with focused implementation updates and comprehensive regression coverage.

No open issues 🎉

What changed in this PR

This pull request preserves valid UTF-8 paths when scanning ELF loader strings, ensuring non-ASCII library and interpreter paths are included in bottle relocation metadata while invalid byte sequences remain excluded.

Changes:

  • Validate ELF loader strings as UTF-8 rather than ASCII-only.
  • Add regression tests for UTF-8 and invalid-encoding RPATHs and interpreter paths.
  • Extend bottle integration coverage for ELF binaries referencing UTF-8 library paths.
File Description
Library/​Homebrew/​test/​keg_relocate/​elf_checker_spec.rb Tests UTF-8 RPATHs, interpreter paths, and invalid UTF-8 rejection.
Library/​Homebrew/​test/​dev-cmd/​bottle_spec.rb Verifies bottle metadata records ELF binaries with UTF-8 library references.
Library/​Homebrew/​keg_relocate.rb Preserves valid UTF-8 ELF relocation strings while rejecting invalid encodings.

Review effort: Lite

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit e92663d Oct 24, 2026
55 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the elf-utf8-relocation-paths branch October 24, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

⌂ 换网址