Skip to content

fix: cap HTTP response buffer at 512 KB to prevent OOM on Pi#110

Merged
GageLawton merged 1 commit into
mainfrom
fix/cap-weather-response-buffer
May 27, 2026
Merged

fix: cap HTTP response buffer at 512 KB to prevent OOM on Pi#110
GageLawton merged 1 commit into
mainfrom
fix/cap-weather-response-buffer

Conversation

@GageLawton
Copy link
Copy Markdown
Owner

Summary

writeCallback in weather.cpp accumulated the full API response into an unbounded std::string. A broken server, misconfigured proxy, or network middlebox returning a large HTML error page could silently exhaust the Pi's limited RAM.

The fix adds a 512 KB hard cap. Normal weatherapi.com responses are ~10 KB, so this gives more than 50× headroom before aborting. Returning 0 from the libcurl write callback causes libcurl to abort with CURLE_WRITE_ERROR, which the existing error path already handles as a failed fetch — no other code changes needed.

Changes

  • src/weather.cpp: add MAX_RESPONSE_BYTES = 512 KB constant; check cumulative buffer size on every write; return 0 to abort and log an error if exceeded

Test plan

  • Confirm normal weather fetches succeed (response is ~10 KB, well under the cap)
  • Confirm the failure is logged clearly and treated as a failed fetch (LCD stays on last good data, backoff kicks in)

writeCallback had no size limit, so a runaway API response (large error
HTML, misconfigured proxy, etc.) could exhaust memory on a Pi with
limited RAM. Adding a 512 KB hard cap — normal weatherapi.com responses
are ~10 KB — and returning 0 from the callback to abort the transfer
with CURLE_WRITE_ERROR, which the existing error-handling path already
treats as a failed fetch.

https://claude.ai/code/session_0166Zd59EUgWgYd3FrphQAio
@GageLawton GageLawton self-assigned this May 27, 2026
@GageLawton GageLawton added the bug Something isn't working label May 27, 2026
@GageLawton GageLawton merged commit 94526ca into main May 27, 2026
2 checks passed
@GageLawton GageLawton deleted the fix/cap-weather-response-buffer branch May 27, 2026 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants