Skip to content

libpcp: reject undersized metadata records in __pmLogLoadMeta - #2663

Open
kurik wants to merge 1 commit into
performancecopilot:mainfrom
kurik:LogMeta
Open

libpcp: reject undersized metadata records in __pmLogLoadMeta#2663
kurik wants to merge 1 commit into
performancecopilot:mainfrom
kurik:LogMeta

Conversation

@kurik

@kurik kurik commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

__pmLogLoadMeta() rejects undersized metadata records
qa/2009: exercise __pmLogLoadMeta undersized metadata record rejection

__pmLogLoadMeta() rejects undersized metadata records
qa/2009: exercise __pmLogLoadMeta undersized metadata record rejection

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved archive metadata validation to safely reject undersized or corrupted records.
    • Corrupted archives now report a clear “Corrupted record” failure instead of being processed incorrectly.
  • Tests

    • Added automated coverage for malformed metadata records and verified that valid archives continue to open successfully.

Walkthrough

Adds record-length validation to both metadata loaders and introduces QA test 2009, which creates malformed archives and verifies pmdumplog reports corrupted records without affecting valid archives.

Changes

Metadata validation

Layer / File(s) Summary
Reject undersized metadata records
src/libpcp/src/logmeta.c, src/libpcp3/src/logmeta.c
Both __pmLogLoadMeta implementations reject negative payload lengths with PM_ERR_LOGREC and use the shared cleanup path.
Crafted archive regression coverage
qa/2009, qa/group
QA test 2009 generates malformed metadata records, verifies valid and corrupted archive behavior, and registers the test in the archive-local group.

Sequence Diagram(s)

sequenceDiagram
  participant pmdumplog
  participant __pmLogLoadMeta
  participant metadata_archive
  pmdumplog->>__pmLogLoadMeta: load metadata records
  __pmLogLoadMeta->>metadata_archive: read crafted record header
  metadata_archive-->>__pmLogLoadMeta: undersized length and type
  __pmLogLoadMeta-->>pmdumplog: report Corrupted record
Loading

Suggested reviewers: kmcdonell, natoscott

Poem

I’m a rabbit guarding metadata tight,
Bad little records now fail just right.
I nibble the headers, check every byte,
Valid archives still hop into sight.
Corrupted ones thump: “Goodnight!”

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: rejecting undersized metadata records in __pmLogLoadMeta.
Description check ✅ Passed The description directly matches the code and QA changes in the pull request.
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.

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.

@coderabbitai coderabbitai Bot 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.

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 `@src/libpcp/src/logmeta.c`:
- Around line 821-827: Enforce remaining-length bounds before every metadata
field and string read in the loaders’ record-parsing paths, including the checks
around the rlen validation in src/libpcp/src/logmeta.c (lines 821-827) and
src/libpcp3/src/logmeta.c (lines 767-773), rejecting zero or undersized positive
payloads without crossing record or allocation boundaries. Extend qa/2009 (lines
63-75) with total lengths 12 through 19 to cover these cases.
🪄 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 YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a9f0fa1-1045-44b5-921d-664eb5655ea9

📥 Commits

Reviewing files that changed from the base of the PR and between 74a4a4f and eed8605.

⛔ Files ignored due to path filters (1)
  • qa/2009.out is excluded by !**/*.out
📒 Files selected for processing (4)
  • qa/2009
  • qa/group
  • src/libpcp/src/logmeta.c
  • src/libpcp3/src/logmeta.c

Comment thread src/libpcp/src/logmeta.c
Comment on lines +821 to +827
if (rlen < 0) {
if (pmDebugOptions.logmeta)
fprintf(stderr, "__pmLogLoadMeta: record len=%d too small (min %d)\n",
h.len, (int)(sizeof(__pmLogHdr) + sizeof(int)));
sts = PM_ERR_LOGREC;
goto end;
}

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.

🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

Enforce payload bounds consistently in both loaders and QA.

The new check rejects negative rlen, but positive undersized records can still make metadata parsing cross record boundaries or read past allocations.

  • src/libpcp/src/logmeta.c#L821-L827: add remaining-length checks before every metadata field/string read.
  • src/libpcp3/src/logmeta.c#L767-L773: apply the same bounded parsing contract.
  • qa/2009#L63-L75: add total lengths 12–19 to cover zero and small positive payloads.
📍 Affects 3 files
  • src/libpcp/src/logmeta.c#L821-L827 (this comment)
  • src/libpcp3/src/logmeta.c#L767-L773
  • qa/2009#L63-L75
🤖 Prompt for 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.

In `@src/libpcp/src/logmeta.c` around lines 821 - 827, Enforce remaining-length
bounds before every metadata field and string read in the loaders’
record-parsing paths, including the checks around the rlen validation in
src/libpcp/src/logmeta.c (lines 821-827) and src/libpcp3/src/logmeta.c (lines
767-773), rejecting zero or undersized positive payloads without crossing record
or allocation boundaries. Extend qa/2009 (lines 63-75) with total lengths 12
through 19 to cover these cases.

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.

1 participant