-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//+build !hz_gb_2312 | ||
|
||
package maddy | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/emersion/go-message/charset" | ||
"golang.org/x/text/encoding" | ||
) | ||
|
||
/* | ||
Disallow hz-gb-2312 encoding as it can trigger OOM crash. | ||
https://github.com/emersion/go-message/issues/95 | ||
https://github.com/golang/go/issues/35118 | ||
*/ | ||
|
||
type dummyEncoding struct{} | ||
|
||
func (dummyEncoding) NewDecoder() *encoding.Decoder { | ||
return &encoding.Decoder{Transformer: dummyEncoding{}} | ||
} | ||
func (dummyEncoding) NewEncoder() *encoding.Encoder { | ||
return &encoding.Encoder{Transformer: dummyEncoding{}} | ||
} | ||
|
||
func (dummyEncoding) Reset() {} | ||
|
||
func (dummyEncoding) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { | ||
return 0, 0, errors.New("hz-gb-2312 decoding is disabled due to known issues") | ||
} | ||
|
||
func init() { | ||
charset.RegisterEncoding("hz-gb-2312", dummyEncoding{}) | ||
} |