Skip to content

Conversation

@sgd2z
Copy link
Contributor

@sgd2z sgd2z commented Dec 9, 2025

Fix infinite loop when parsing MagicMock objects

Problem

When llsd.parse() receives a MagicMock object (or similar mock objects), it enters an infinite loop that consumes all available memory until the process is killed with OOM.

This commonly occurs when tests incorrectly mock requests.Response without setting the .content attribute - the default MagicMock is passed to llsd.parse() instead of bytes.

Root Cause

In LLSDBaseParser._reset(), the code checked something.seekable() to determine if the input was a seekable stream. For a MagicMock:

  • mock.seekable() returns another MagicMock (which is truthy)
  • The parser then tries to read from the mock, getting more MagicMock objects recursively
  • This causes infinite memory consumption

Solution

Modified _reset() to validate input types properly:

  • Check if something is an io.IOBase instance (proper stream type)
  • Raise a clear LLSDParseError for invalid input types

Changes

  • llsd/base.py: Added proper input validation in _reset() method
  • tests/llsd_test.py: Added InvalidInputTypes test class with tests for MagicMock, str, None, and int inputs

Testing

All 96 tests pass.

Before this fix:
llsd.parse(MagicMock()) # Hangs forever, consumes all memory

After this fix:
llsd.parse(MagicMock())

Raises: LLSDParseError: Cannot parse LLSD from MagicMock. Expected bytes or a file-like object (io.IOBase subclass).

dependabot bot and others added 2 commits December 1, 2025 13:45
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v4...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
@github-actions
Copy link

github-actions bot commented Dec 9, 2025

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@sgd2z
Copy link
Contributor Author

sgd2z commented Dec 9, 2025

I have read the CLA Document and I hereby sign the CLA

@sgd2z
Copy link
Contributor Author

sgd2z commented Dec 9, 2025

CLA Assistant Lite bot: Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.

I have read the CLA Document and I hereby sign the CLA

You can retrigger this bot by commenting recheck in this Pull Request

recheck

sgd2z added 3 commits December 9, 2025 22:50
Debian Buster reached end-of-life and its repositories are no longer
available at deb.debian.org. This updates the CI to use archive.debian.org
for the Python 2.7 build which requires the Buster image.
@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.82%. Comparing base (f00d36b) to head (8a0618f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #32      +/-   ##
==========================================
+ Coverage   89.68%   89.82%   +0.13%     
==========================================
  Files           6        6              
  Lines         863      865       +2     
==========================================
+ Hits          774      777       +3     
+ Misses         89       88       -1     

☔ 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.

@sgd2z sgd2z requested a review from nattylinden December 11, 2025 17:18
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.

2 participants