You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
net: IPMask.MarshalText silently returns empty output for masks that are not 4 or 16 bytes long #81749
net.IPMask.MarshalText gained a new text format in the Go 1.28 cycle (issue #29678), gated behind GODEBUG=netmarshal=1. For a mask whose length is not 0, 4, or 16 bytes, the new path returns empty bytes with a nil error instead of an error, and the data is silently destroyed:
m:= net.IPMask{255, 255, 255, 0, 1}
b, err:=m.MarshalText() // GODEBUG=netmarshal=1: b="", err=nilj, _:=json.Marshal(m) // j = ""varm2 net.IPMaskjson.Unmarshal(j, &m2) // m2 = [] -- the original 5 bytes are gone
(The old base64 format round-trips the same mask fine.)
The ok result is discarded; on failure addr is the zero Addr and AppendTo(nil) yields nothing. The sibling IP.MarshalText returns an honest error (address 0102030405: invalid IP address) for invalid lengths, so this is also internally inconsistent. The existing ipMaskJSONTests table only covers nil/4-byte/16-byte masks, which is why it slipped through.
Expected: MarshalText returns a non-nil error for a mask that cannot be represented as an IP address.
Seen on master at 8190b02c (2026-09-25), linux/amd64, go1.28-devel.
@dajiaohuang Please never send code patches in the issue tracker. For copyright reasons we can only use patches that go through the contribution process (https://go.dev/doc/contribute). Patches in the issue tracker make our work harder, not easier. Thanks.
I sent https://go.dev/cl/848108, which uses the old marshaling for invalid IPMask values rather than returning an error. That seems best for backward compatibility.
Activity
gabyhelp commentedon Sep 25, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
dajiaohuang commentedon Sep 25, 2026
prattmic commentedon Sep 29, 2026
cc @neild @nicholashusin @seankhliao
prattmic commentedon Sep 29, 2026
Marked as a release blocker to ensure this is investigated before the 1.28 release.
ianlancetaylor commentedon Sep 29, 2026
I will take a look at this.
@dajiaohuang Please never send code patches in the issue tracker. For copyright reasons we can only use patches that go through the contribution process (https://go.dev/doc/contribute). Patches in the issue tracker make our work harder, not easier. Thanks.
dajiaohuang commentedon Oct 7, 2026
非常抱歉在issue中直接贴了代码patch,给各位维护者添麻烦了。我理解Go项目只能通过Gerrit贡献流程接收patch(https://go.dev/doc/contribute),这是出于版权原因的必要流程。后续如果我认为有合适的修复方案,会严格按照贡献流程通过Gerrit提交。再次致歉!
cagedmantis commentedon Oct 13, 2026
Just a note: IPMask.MarshalText has been discussed in the proposal committee recently. There may be a need to revisit this.
gopherbot commentedon Oct 13, 2026
Change https://go.dev/cl/848108 mentions this issue:
net: marshal and unmarshal invalid IPMask valuesianlancetaylor commentedon Oct 14, 2026
I sent https://go.dev/cl/848108, which uses the old marshaling for invalid
IPMaskvalues rather than returning an error. That seems best for backward compatibility.net: marshal and unmarshal invalid IPMask values