Repository navigation
Fix macOS process arguments corrupting after a non-ASCII entry - #3577
Conversation
getArguments() and getEnvironmentVariables() corrupted every entry after one containing a non-ASCII character. Both backends walked the sysctl buffer advancing the offset by the decoded String's length, which counts UTF-16 chars, over a buffer of UTF-8 bytes. A multi-byte character makes the entry longer in bytes than in chars, so the next read starts mid-character and every subsequent entry is misaligned. Observed on macOS 15 against /bin/sh -c 'sleep 400; true' with the arguments 日本語テスト, café, plain-ascii-tail. Both backends reported the first correctly, then "語テスト" and a replacement-character string in place of the last two, which were dropped entirely. An ASCII-only control process parsed correctly on both. The twins were wrong in agreement rather than divergent -- JNA advanced by arg.length() and FFM by arg.length() + 1, the latter landing on the null terminator only for single-byte entries -- so a JNA/FFM comparison could not have caught it. Hoist the parse into MacOSProcess.parseProcArgs(byte[], int) in oshi-common, leaving each backend the sysctl call and a byte-array copy of the returned length. Offsets now advance to the next null byte and each entry is decoded as UTF-8 over its own byte range, which also removes the "skip exec_command by string length" step that had the same flaw. Only the sysctl-reported size is copied, not the full ARGMAX buffer. Adds MacOSProcessTest covering multi-byte arguments and environment values, null padding between sections, the exec_path entry, the size bound, and the unusable-buffer cases. Reverting the parser to the char-length advance fails the multi-byte test. Verified on an Apple Silicon host: both backends now report arguments identical to ps and to each other, and the self-process environment read is unchanged at 54 entries.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (8)
📝 WalkthroughWalkthroughChangesThe macOS macOS process argument parsing
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3577 +/- ##
============================================
- Coverage 80.00% 79.98% -0.03%
Complexity 3846 3846
============================================
Files 709 709
Lines 24207 24206 -1
Branches 4049 4048 -1
============================================
- Hits 19366 19360 -6
- Misses 2687 2690 +3
- Partials 2154 2156 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java`:
- Around line 250-252: Remove the fixed 1,024-argument cap in MacOSProcess
argument parsing by validating nargs against a bound derived from the available
procargs buffer size, while retaining the positive-count and impossible-count
safeguards. In
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java lines
250-252, update the guard accordingly; in
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
lines 111-112, preserve the impossible-count test and add a valid fixture
containing more than 1,024 arguments.
- Around line 255-276: The argument parser in MacOSProcess must preserve empty
argv entries instead of treating all NUL bytes as padding. After the initial
padding following exec_path, consume exactly nargs null-terminated entries,
including zero-length entries, before parsing environment entries; update the
related coverage in MacOSProcessTest.java lines 77-83 to verify this behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 72ee1d6b-7e97-4003-a2c8-ad83b9b355d5
📒 Files selected for processing (5)
CHANGELOG.mdoshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.javaoshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 21, ubuntu-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
📓 Path-based instructions (10)
**/*.{java,xml,properties,md}
📄 CodeRabbit inference engine (AGENTS.md)
Do not commit generated output,
target/, or IDE files.
Files:
CHANGELOG.mdoshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
CHANGELOG.md
📄 CodeRabbit inference engine (AGENTS.md)
Add a
Next Releasechangelog entry only for user-visible changes; omit pure refactors, deduplication, test-only changes, and CI configuration changes.
Files:
CHANGELOG.md
**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/*.java: Do not use banned numeric parsing APIs such asInteger.parseInt,Long.parseLong,Double.parseDouble, orInteger.decode; use the corresponding tolerantParseUtilmethods.
Do not importorg.slf4j.event.**; useoshi.util.LogLevelinstead.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
**/src/test/java/**/*Test.java
📄 CodeRabbit inference engine (AGENTS.md)
Write tests against parsing and transformation methods using fixture data; keep acquisition methods thin. Do not add Mockito, and use JUnit 5 with Hamcrest.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
**/*Test.java
📄 CodeRabbit inference engine (AGENTS.md)
Test hardware-dependent behavior using invariants, plausible ranges, correct types, and ordering rather than fixed machine-specific values; treat zero and empty results as valid where applicable.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
oshi-common/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
oshi-common/src/main/java/**/*.java: Keeposhi-commonpure Java: do not reference JNA, FFM (java.lang.foreign), orSystem.load/loadLibrary; place parsing, conversion, validation, caching, and shared implementation logic here when it is not native-API-specific.
Before adding a general parsing helper, checkoshi.util.ParseUtil; use its existing parsing methods or add shared primitives there rather than duplicating parsers in platform drivers.
Read runtime configuration fromoshi-common/src/main/resources/oshi.propertiesthroughGlobalConfigor Java system properties; do not introduce a separate configuration mechanism.
Files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
{oshi-common,oshi-core}/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
Use Java 8 language and API compatibility: do not use
var, records, switch expressions, text blocks,List.of,Stream.toList(), or other post-Java-8 features.
Files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java
**/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/src/main/java/**/*.java: Keep external imports synchronized withconfig/import-control.xml, the module'smodule-info.java, and, when necessary, its Maven configuration.
Provide Javadoc for every public and protected type and method; use imported simple class names rather than fully qualified names in code and Javadoc links.
Use the repository's concurrency annotation (@ThreadSafe,@Immutable,@NotThreadSafe, or@GuardedBy) on new classes, matching the modeled class where appropriate.
Memoize constant or expensive, slowly changing system values withoshi.util.Memoizer.memoize, generally using aSupplier<T>anddefaultExpiration()when refresh is required.
Do not duplicate non-native logic between platform implementations; hoist parsing, conversion, filtering, caching, validation, and sentinel handling intooshi-commonwhere possible.
Files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
oshi-core/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
For changes to an
oshi-coreimplementation, apply the equivalent behavior change to its correspondingoshi-core-ffmtwin, or explain why the implementations intentionally differ.
Files:
oshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java
oshi-core-ffm/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
oshi-core-ffm/src/main/java/**/*.java: For changes to anoshi-core-ffmimplementation, apply the equivalent behavior change to its correspondingoshi-coretwin, or explain why the implementations intentionally differ.
Do not referencecom.sun.jnafrom FFM implementation sources.
Files:
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
🧠 Learnings (6)
📚 Learning: 2026-08-03T00:46:14.953Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3566
File: oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java:18-22
Timestamp: 2026-08-03T00:46:14.953Z
Learning: In the OSHI Java codebase, do not require duplicate Javadoc on public methods annotated with Override when the inherited Javadoc from the parent declaration adequately documents the method. The general public-member Javadoc requirement should not flag these overrides solely because they lack redundant documentation.
Applied to files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.
Applied to files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
📚 Learning: 2026-07-30T00:35:22.638Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3547
File: oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java:82-82
Timestamp: 2026-07-30T00:35:22.638Z
Learning: In OSHI, treat changes as “API-breaking” only when they affect classes (or relevant API surface) annotated with `PublicAPI`. Public classes/members that are not annotated with `PublicAPI` should be reviewed as internal implementation details, even if they are public (e.g., classes like `oshi.hardware.common.platform.unix.BsdFirmware`). Also, respect intentional visibility decisions used for tests—e.g., methods like `BsdFirmware.parseDmesg(List<String>)` may be intentionally package-private to support tests within the same package; avoid widening visibility or altering signatures unless the related `PublicAPI` contract requires it.
Applied to files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java
📚 Learning: 2026-08-02T23:56:23.866Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3565
File: oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java:51-56
Timestamp: 2026-08-02T23:56:23.866Z
Learning: For Java FFM bindings in the oshi-core-ffm module, assume a 64-bit JVM and 64-bit operating system. Do not flag 32-bit native ABI or memory-layout compatibility concerns, consistent with the project's JDK 25 support policy, unless that policy changes.
Applied to files:
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
🪛 ast-grep (0.45.0)
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
[warning] 48-48: Use a randomly-generated IV
Context: byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
Note: [CWE-329] Generation of Predictable IV with CBC Mode.
(random-iv)
🔇 Additional comments (3)
CHANGELOG.md (1)
13-13: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java (1)
144-152: LGTM!oshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java (1)
100-110: LGTM!
Two problems in the KERN_PROCARGS2 parser, both confirmed against live processes on macOS 15. An empty string is a legal argv entry, but the parser treated every null as padding between entries, so it skipped over one. A process launched with argv ["/bin/sh", "-c", "sleep 300; true", "first", "", "third"] reported five arguments with the empty one missing. Worse than the drop: nargs is never decremented for the skipped entry, so the argument count runs one past the end of argv and pulls the first environment entry into the argument list. The arguments are contiguous, so consume exactly nargs of them after the padding that follows exec_path, allowing zero-length entries, and only then treat nulls as separators while reading the environment. Separately, the inherited "nargs <= 1024" sanity check discarded the whole buffer for any process with more arguments, which is not unusual: a shell glob or a compiler invocation reaches thousands. `/bin/sh -c ... $(seq 1 1200)` reported zero arguments and zero environment variables. Bound nargs by the bytes actually available instead, since every argument occupies at least its own null terminator. That still rejects an impossible count from a corrupt buffer, which the existing test covers. Adds coverage for an empty argument between two populated ones, for 1999 arguments, and for padding between exec_path and argv[0], which the fixtures did not previously model. Verified on an Apple Silicon host: both backends now report six arguments with the empty slot intact, 1203 arguments for the seq case, and the non-ASCII case from the previous commit still parses correctly.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java`:
- Around line 263-280: Update the argument and environment parsing in
MacOSProcess so entries whose nextNull result equals limit are not decoded or
added; stop parsing before decode in both loops. Add coverage for a size limit
that truncates the middle of an argument and an environment value, ensuring
neither partial entry is returned.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 130db232-24b7-4343-81b1-31d335bce46a
📒 Files selected for processing (2)
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.javaoshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 21, ubuntu-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/*.java: Do not use banned numeric parsing APIs such asInteger.parseInt,Long.parseLong,Double.parseDouble, orInteger.decode; use the corresponding tolerantParseUtilmethods.
Do not importorg.slf4j.event.**; useoshi.util.LogLevelinstead.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
**/src/test/java/**/*Test.java
📄 CodeRabbit inference engine (AGENTS.md)
Write tests against parsing and transformation methods using fixture data; keep acquisition methods thin. Do not add Mockito, and use JUnit 5 with Hamcrest.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
**/*Test.java
📄 CodeRabbit inference engine (AGENTS.md)
Test hardware-dependent behavior using invariants, plausible ranges, correct types, and ordering rather than fixed machine-specific values; treat zero and empty results as valid where applicable.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
**/*.{java,xml,properties,md}
📄 CodeRabbit inference engine (AGENTS.md)
Do not commit generated output,
target/, or IDE files.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
oshi-common/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
oshi-common/src/main/java/**/*.java: Keeposhi-commonpure Java: do not reference JNA, FFM (java.lang.foreign), orSystem.load/loadLibrary; place parsing, conversion, validation, caching, and shared implementation logic here when it is not native-API-specific.
Before adding a general parsing helper, checkoshi.util.ParseUtil; use its existing parsing methods or add shared primitives there rather than duplicating parsers in platform drivers.
Read runtime configuration fromoshi-common/src/main/resources/oshi.propertiesthroughGlobalConfigor Java system properties; do not introduce a separate configuration mechanism.
Files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
{oshi-common,oshi-core}/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
Use Java 8 language and API compatibility: do not use
var, records, switch expressions, text blocks,List.of,Stream.toList(), or other post-Java-8 features.
Files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
**/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/src/main/java/**/*.java: Keep external imports synchronized withconfig/import-control.xml, the module'smodule-info.java, and, when necessary, its Maven configuration.
Provide Javadoc for every public and protected type and method; use imported simple class names rather than fully qualified names in code and Javadoc links.
Use the repository's concurrency annotation (@ThreadSafe,@Immutable,@NotThreadSafe, or@GuardedBy) on new classes, matching the modeled class where appropriate.
Memoize constant or expensive, slowly changing system values withoshi.util.Memoizer.memoize, generally using aSupplier<T>anddefaultExpiration()when refresh is required.
Do not duplicate non-native logic between platform implementations; hoist parsing, conversion, filtering, caching, validation, and sentinel handling intooshi-commonwhere possible.
Files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
🧠 Learnings (4)
📚 Learning: 2026-08-03T00:46:14.953Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3566
File: oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java:18-22
Timestamp: 2026-08-03T00:46:14.953Z
Learning: In the OSHI Java codebase, do not require duplicate Javadoc on public methods annotated with Override when the inherited Javadoc from the parent declaration adequately documents the method. The general public-member Javadoc requirement should not flag these overrides solely because they lack redundant documentation.
Applied to files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.
Applied to files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
📚 Learning: 2026-07-30T00:35:22.638Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3547
File: oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java:82-82
Timestamp: 2026-07-30T00:35:22.638Z
Learning: In OSHI, treat changes as “API-breaking” only when they affect classes (or relevant API surface) annotated with `PublicAPI`. Public classes/members that are not annotated with `PublicAPI` should be reviewed as internal implementation details, even if they are public (e.g., classes like `oshi.hardware.common.platform.unix.BsdFirmware`). Also, respect intentional visibility decisions used for tests—e.g., methods like `BsdFirmware.parseDmesg(List<String>)` may be intentionally package-private to support tests within the same package; avoid widening visibility or altering signatures unless the related `PublicAPI` contract requires it.
Applied to files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
🔇 Additional comments (2)
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java (1)
289-296: LGTM!oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java (1)
13-13: LGTM!Also applies to: 37-53, 90-128, 156-159
Both parse loops decoded whatever bytes remained when nextNull found no terminator before the limit, so a size that cut through the middle of an entry yielded a fragment: a buffer truncated two bytes into "kept" returned "kep" as an argument, and one cut inside an environment value returned a short value under the right key. A truncated value is worse than a missing one, since a caller cannot tell it is incomplete. Stop before decoding in both loops when the entry has no terminator. This is defensive rather than a live fix: the sysctl reports the length it wrote and the kernel writes whole null-terminated strings, so a well-formed buffer ends every entry before the limit. Verified on an Apple Silicon host that real processes are unaffected -- the non-ASCII and empty argument cases and the self-process environment read are all unchanged on both backends. Adds coverage truncating the middle of an argument and the middle of an environment value; both fail without the guard.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java`:
- Around line 153-155: Update the truncation boundary argument in
MacOSProcess.parseProcArgs so it uses argBuf.length - 7, matching the comment’s
intended two-byte fragment of the "kept" entry; leave the surrounding test setup
unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: dcab13ac-12b5-424a-afbd-ffa6e430f57e
📒 Files selected for processing (2)
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.javaoshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
- oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
- GitHub Check: Test JDK 21, ubuntu-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
- GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
📓 Path-based instructions (4)
**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/*.java: Do not use banned numeric parsing APIs such asInteger.parseInt,Long.parseLong,Double.parseDouble, orInteger.decode; use the corresponding tolerantParseUtilmethods.
Do not importorg.slf4j.event.**; useoshi.util.LogLevelinstead.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
**/src/test/java/**/*Test.java
📄 CodeRabbit inference engine (AGENTS.md)
Write tests against parsing and transformation methods using fixture data; keep acquisition methods thin. Do not add Mockito, and use JUnit 5 with Hamcrest.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
**/*Test.java
📄 CodeRabbit inference engine (AGENTS.md)
Test hardware-dependent behavior using invariants, plausible ranges, correct types, and ordering rather than fixed machine-specific values; treat zero and empty results as valid where applicable.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
**/*.{java,xml,properties,md}
📄 CodeRabbit inference engine (AGENTS.md)
Do not commit generated output,
target/, or IDE files.
Files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
🧠 Learnings (1)
📚 Learning: 2026-08-03T00:46:14.953Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3566
File: oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java:18-22
Timestamp: 2026-08-03T00:46:14.953Z
Learning: In the OSHI Java codebase, do not require duplicate Javadoc on public methods annotated with Override when the inherited Javadoc from the parent declaration adequately documents the method. The general public-member Javadoc requirement should not flag these overrides solely because they lack redundant documentation.
Applied to files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java
🔇 Additional comments (1)
oshi-common/src/test/java/oshi/software/common/os/mac/MacOSProcessTest.java (1)
1-64: LGTM!Also applies to: 66-145, 147-152, 156-163, 165-182
The mid-argument truncation case cut 6 bytes from the end, leaving a three-byte fragment "kep" where the comment claims two. Cut 7 so the fragment is "ke", matching the description. Same code path either way; removing the guard still fails the assertion, now with the fragment the comment names.
Summary
macOS
OSProcess#getArguments()andgetEnvironmentVariables()corrupt every entry after one containing a non-ASCII character. Both backends walk theKERN_PROCARGS2sysctl buffer advancing the offset by the decodedString's length — which counts UTF-16 chars — over a buffer of UTF-8 bytes. One multi-byte character makes the entry longer in bytes than in chars, so the next read starts mid-character and everything downstream is misaligned.Found while sweeping the
MacOSProcesstwin pair, continuing the normalized JNA/FFM diff that produced #3569. Notably this is not a divergence — the twins are wrong in agreement (JNA advances byarg.length(), FFM byarg.length() + 1, which lands on the null terminator only for single-byte entries), so a twin comparison could not have caught it. It showed up because reading the two side by side made the offset arithmetic the thing under scrutiny.Reproduction
Against
/bin/sh -c 'sleep 400; true' 日本語テスト café plain-ascii-tailon macOS 15 (Apple Silicon):[3]日本語テスト日本語テスト[4]語テスト✗café[5]<28><28>スト✗plain-ascii-tailcaféandplain-ascii-tailwere dropped entirely rather than merely mangled. Both backends were damaged identically in kind. An ASCII-only control process with the same shape parsed correctly on both, confirming the trigger.The fix
Hoist the parse into
MacOSProcess.parseProcArgs(byte[], int)inoshi-common, per the "extract the parsing from the acquisition" guidance — each backend keeps only its sysctl call plus a byte-array copy of the returned length, and the shared parser advances to the next null byte and decodes each entry as UTF-8 over its own byte range. That also removes the "skipexec_commandby string length" step, which had the same flaw at the head of the buffer.Only the sysctl-reported size is copied, not the full
ARGMAXallocation.Tests
MacOSProcessTestcovers multi-byte arguments and multi-byte environment values, null padding between sections, theexec_pathentry that the first argument repeats, the size bound, and the unusable-buffer cases (short buffer, zero/negative/oversizednargs).Reverting the parser to the char-length advance fails
testMultiByteArgsDoNotShiftLaterEntries, so the test is a real guard rather than a passing decoration.Verification
Full
./mvnw clean spotless:apply sortpom:sort checkstyle:check install forbiddenapis:check javadoc:javadocreactor build green on JDK 26. Live on an Apple Silicon host, both backends now report arguments identical topsand to each other, and the self-process environment read is unchanged at 54 entries.One thing checked and ruled out: the environment map is empty for those child processes, but
ps -Ewwshows no environment for them either, so that is a macOS restriction OSHI is correctly matching, not a second bug.Summary by CodeRabbit
Bug Fixes
Documentation