fix: cap HTTP response buffer at 512 KB to prevent OOM on Pi#110
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
writeCallbackinweather.cppaccumulated the full API response into an unboundedstd::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
0from the libcurl write callback causes libcurl to abort withCURLE_WRITE_ERROR, which the existing error path already handles as a failed fetch — no other code changes needed.Changes
src/weather.cpp: addMAX_RESPONSE_BYTES = 512 KBconstant; check cumulative buffer size on every write; return 0 to abort and log an error if exceededTest plan