Go1.16.1 發(fā)布:這個 Bug 有點 Low
閱讀本文大概需要 4 分鐘。
Go 1.16 是 2021 年 2 月 16 日發(fā)布的。新版本發(fā)布,大家一般會等等,坐等 1.16.1 發(fā)布。沒想到快一個月了才等到。
和之前一樣,小版本是修復 Bug,會同時發(fā)布兩個版本,這次是 Go1.16.1 和 Go1.15.9。那具體什么 Bug 呢?
Bug 1:encoding/xml 包相關
這個 Bug 不是 1.16 引入的,而是之前版本就存在。所以,Go 1.15.9 也修復了該 Bug。
具體是:在通過 xml.NewTokenDecoder 獲得一個 Decoder 指針時,如果參數(shù) TokenReader 是自定義的,可能會出現(xiàn)死循環(huán)。
The Decode, DecodeElement, and Skip methods of an xml.Decoder provided by xml.NewTokenDecoder may enter an infinite loop when operating on a custom xml.TokenReader which returns an EOF in the middle of an open XML element.
詳情見 issue:https://github.com/golang/go/issues/44915。
Bug 2:archive/zip 包相關
當調用該包中的 Render.Open 方法時,如果 zip 包含以 ../ 開頭的文件,該方法會 panic。這個方法是 Go1.16 新增的,因為返回了 io/fs.File 類型。
func (r *Reader) Open(name string) (fs.File, error)
當跟蹤修復該 Bug 的代碼時,有點掉價。。。(見:https://github.com/golang/go/commit/634d28d78ccbeb6e86f8bfeba030ea8be518f8fa)

完整的修復前的代碼:
func toValidName(name string) string {
name = strings.ReplaceAll(name, `\`, `/`)
p := path.Clean(name)
if strings.HasPrefix(p, "/") {
p = p[len("/"):]
}
for strings.HasPrefix(name, "../") {
p = p[len("../"):]
}
return p
}
通過 for 循環(huán)處理 p 中的 ../,結果 for 里面用的卻是 name 變量,這個 bug 有點 low。。。可見大神們也有犯低級錯誤的時候。所以,如果你團隊成員偶爾犯了低級錯誤,別太責備,讓他抄寫對應 Bug 100 遍即可,哈哈哈哈!
以上兩個 Bug 都定義為安全問題。Go Team 正在為 Go 版本中的漏洞提出一個新的安全策略。有興趣的可以參與討論:https://github.com/golang/go/issues/44918。
如果你使用了 Go1.16,而且可能用了 zip 包,建議大家升級到 Go1.16.1 版本。而 xml,可能很多人都沒用到?!Go 語言中文網已經為你準備好了下載地址:https://studygolang.com/dl,當然也可以使用喜歡的方式升級。
歡迎關注我
