Fix: panic on empty MaxMind CSV, unchecked writer errors and entry reuse in the private plugin - #356
Closed
Loyalsoldier with Claude wants to merge 4 commits into
Closed
Fix: panic on empty MaxMind CSV, unchecked writer errors and entry reuse in the private plugin#356Loyalsoldier with Claude wants to merge 4 commits into
Loyalsoldier with Claude wants to merge 4 commits into
Conversation
…riters Agent-Logs-Url: https://github.com/Loyalsoldier/geoip/sessions/051395fa-8215-474c-b4a5-423d84a33e0c Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Claude created this pull request from a session on behalf of
Loyalsoldier
July 28, 2026 09:41
View session
Loyalsoldier
marked this pull request as ready for review
July 29, 2026 10:35
There was a problem hiding this comment.
Pull request overview
Fixes multiple correctness issues across plugins, primarily around safe entry handling, input validation, and ensuring writer/close/flush errors aren’t silently dropped when producing output artifacts.
Changes:
privateinput plugin now always builds a freshPRIVATEentry before applying add/remove, avoiding mutation of shared container state.- MaxMind country-locations CSV parsing now rejects empty input instead of panicking.
- Output writers now attempt to surface zstd flush/close errors and check file close errors before logging success.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| plugin/special/private.go | Avoids mutating an existing shared PRIVATE entry by always creating a new entry. |
| plugin/maxmind/maxmind_country_csv_in.go | Prevents panic on empty CSV by returning a structured error early. |
| plugin/mihomo/mrs_out.go | Propagates zstd encoder close/flush errors and explicitly closes output files. |
| plugin/singbox/srs_out.go | Explicitly closes output files and checks close errors before logging success. |
| plugin/maxmind/maxmind_country_mmdb_out.go | Explicitly closes MMDB output file and checks close errors before logging success. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
168
to
171
| err = m.convertToMrs(ipRanges, f) | ||
| if err != nil { | ||
| return err | ||
| } |
Comment on lines
384
to
387
| _, err = writer.WriteTo(f) | ||
| if err != nil { | ||
| return err | ||
| } |
Comment on lines
187
to
190
| err = srs.Write(f, *ruleset, constant.RuleSetVersion1) | ||
| if err != nil { | ||
| return err | ||
| } |
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.
Fixes five bugs found by reading through the codebase.
Bugs fixed
1.
privateinput plugin mutated the container's shared entry (plugin/special/private.go)It fetched the existing
PRIVATEentry out of the container and added CIDRs to it directly. Two consequences:onlyIPTypefilter was bypassed — private CIDRs went straight into the shared entry instead of throughcontainer.Add's filtering, so e.g.onlyIPType: ipv4still injected IPv6 private CIDRs whenever aPRIVATElist already existed.action: remove,container.Removeended up removing the entry's own set from itself, wiping the entire list.It now always builds a fresh entry, matching what the
testplugin does.2. Panic on empty CSV (
plugin/maxmind/maxmind_country_csv_in.go)getCountryCodedidlines[1:]without a length check, panicking on an empty country-locations CSV. It now returns an error.3. Discarded zstd flush error (
plugin/mihomo/mrs_out.go)convertToMrsuseddefer encoder.Close(), dropping the error from the final flush, so a failed write produced a silently truncated.mrsfile. The close error is now propagated via a named return.4. Discarded file close errors (
plugin/mihomo/mrs_out.go,plugin/singbox/srs_out.go)Both output writers only closed the file via
defer, discarding close errors and logging✅before the data was known to be flushed. Both now close explicitly and check the error before logging.