Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Gaurav23V
Copy link
Contributor

This PR prevents GDB from crashing due to OOM errors when hexdump is called with an excessively large count.

It introduces a check before attempting the memory read, comparing the requested count against a new configurable limit. If the count exceeds the limit, a ValueError is raised with an informative message guiding the user on how to adjust the limit.

  • Adds a new configuration parameter: hexdump-limit-mb
    • Default value: 10 (MB)
    • Setting to 0 disables the limit check.
  • Includes tests to verify the limit check, error message, and configurability.

Fixes #2608

@codecov
Copy link

codecov bot commented Mar 27, 2025

Codecov Report

Attention: Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 9.93%. Comparing base (a229b29) to head (ad41236).
Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
pwndbg/commands/hexdump.py 33.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             dev   #2803      +/-   ##
========================================
+ Coverage   5.44%   9.93%   +4.49%     
========================================
  Files        225     223       -2     
  Lines      25493   25424      -69     
  Branches    3863    3855       -8     
========================================
+ Hits        1388    2527    +1139     
+ Misses     23914   22460    -1454     
- Partials     191     437     +246     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

help_docstring="""Set the maximum size in megabytes (MB) that the `hexdump` command will attempt to read at once.
Prevents GDB crashes due to excessive memory allocation requests.
Set to 0 for unlimited (use with caution).""",
param_class=3,
Copy link
Member

Choose a reason for hiding this comment

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

What is param_class?

Copy link
Contributor Author

@Gaurav23V Gaurav23V Mar 27, 2025

Choose a reason for hiding this comment

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

The value 3 corresponds to PARAM_ZUINTEGER, which means "Unsigned integer, allows 0". This is the correct type for hexdump-limit-mb because the limit should be a non-negative number of megabytes, and we specifically want to allow 0 as a valid value to signify "unlimited".

I initially encountered a mypy type-checking error when trying to import and use the PARAM_ZUINTEGER constant directly (it was incorrectly inferred as the wrong type). As a temporary workaround during debugging, I used the literal value 3. I mistakenly forgot to revert this to the proper method, which involves importing the constant correctly, before submitting the PR.

@Gaurav23V
Copy link
Contributor Author

Updated the code to use the correct import from pwndbg.lib.config import PARAM_ZUINTEGER and the PARAM_ZUINTEGER constant for param_class.
If there is something else which is not appropriate please let me know.

@disconnect3d disconnect3d merged commit a82e152 into pwndbg:dev Mar 28, 2025
23 of 24 checks passed
@disconnect3d
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

hexdump should not crash gdb due to OOM when too huge count is passed

2 participants