Skip to content

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
masterfrom
claude/find-and-fix-potential-bugs
Closed

Fix: panic on empty MaxMind CSV, unchecked writer errors and entry reuse in the private plugin#356
Loyalsoldier with Claude wants to merge 4 commits into
masterfrom
claude/find-and-fix-potential-bugs

Conversation

@Claude

@Claude Claude AI commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Fixes five bugs found by reading through the codebase.

Bugs fixed

1. private input plugin mutated the container's shared entry (plugin/special/private.go)

It fetched the existing PRIVATE entry out of the container and added CIDRs to it directly. Two consequences:

  • The onlyIPType filter was bypassed — private CIDRs went straight into the shared entry instead of through container.Add's filtering, so e.g. onlyIPType: ipv4 still injected IPv6 private CIDRs whenever a PRIVATE list already existed.
  • With action: remove, container.Remove ended up removing the entry's own set from itself, wiping the entire list.

It now always builds a fresh entry, matching what the test plugin does.

2. Panic on empty CSV (plugin/maxmind/maxmind_country_csv_in.go)

getCountryCode did lines[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)

convertToMrs used defer encoder.Close(), dropping the error from the final flush, so a failed write produced a silently truncated .mrs file. 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.

…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>
@Loyalsoldier Loyalsoldier changed the title Fix several latent bugs in entry caching, private input and output writers Fix: panic on empty MaxMind CSV, unchecked writer errors and entry reuse in the private plugin Jul 29, 2026
@Loyalsoldier
Loyalsoldier marked this pull request as ready for review July 29, 2026 10:35
Copilot AI review requested due to automatic review settings July 29, 2026 10:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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:

  • private input plugin now always builds a fresh PRIVATE entry 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 thread plugin/mihomo/mrs_out.go
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 thread plugin/singbox/srs_out.go
Comment on lines 187 to 190
err = srs.Write(f, *ruleset, constant.RuleSetVersion1)
if err != nil {
return err
}
@Loyalsoldier
Loyalsoldier deleted the claude/find-and-fix-potential-bugs branch July 29, 2026 10:52
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.

3 participants