Skip to content

Conversation

@vanserox
Copy link
Contributor

While buffer.go uses int32 type size not uint32 type, malformed dns response causes ReadFullFrom with negative size which leading to slice bounds out of range panic.

Here is the panic log (my dns server has additional fields):
2025/10/15 17:05:11.712529[Error] app/dns: failed to read response length > io: read/write on closed pipe panic: runtime error: slice bounds out of range [:-21477] goroutine 9214 [running]: github.com/xtls/xray-core/common/buf. (*Buffer).ReadFullFrom(Ox5af0a27200?, [Ox6f45a34200?,0x4000baad20?],0xf14d26c0?) github.com/xtls/xray-core/common/buf/ buffer.go:340 +0x23c github com/xtls/xray-core/app) dns.(*TCPNameServ er).sendQuery. func1(0x4000baac30) github. com/xtls/xray-core/ app/dns/ nameserver_tcp.go:184 +0x9c4 created by github.com/xtls/xray- core/app/dns. (*TCPNameServer) sendQuery in gor outine 9213 github.com/xtls/xray- core/app/dns/ nameserver. tcp.go:115 +0x274

@Fangliding
Copy link
Member

跟下面out of bound合一起吧 if end > int32(len(b.v)) || end < int32(b.end)

@vanserox vanserox reopened this Oct 16, 2025
@vanserox
Copy link
Contributor Author

跟下面out of bound合一起吧 if end > int32(len(b.v)) || end < int32(b.end)

done.

@Fangliding
Copy link
Member

Fangliding commented Oct 16, 2025

我先前的要求不太对 我重新检查了一下dns over tcp的实现 它将长度读取为int16 但是实际数据类型是uint16 因为正数时二者的二进制布局刚好一致导致了问题 修正后应该没有问题了 可以按原设计抛出错误
之前好像就有过负数检查 但还是留下了panic 不然这个问题还没法发现(

@vanserox
Copy link
Contributor Author

vanserox commented Oct 16, 2025

我先前的要求不太对 我重新检查了一下dns over tcp的实现 它将长度读取为int16 但是实际数据类型是uint16 因为正数时二者的二进制布局刚好一致导致了问题 修正后应该没有问题了 可以按原设计抛出错误 之前好像就有过负数检查 但还是留下了panic 不然这个问题还没法发现(

potential same panic in another code as well.

n, err = respBuf.ReadFullFrom(conn, int32(length))

common.Must2(bb.ReadFullFrom(rand.Reader, int32(nonceSize)))

if _, err := b.ReadFullFrom(r.Reader, length); err != nil {

ReadFullFrom as a common util function, it's better to add negative size check.

@Fangliding
Copy link
Member

quic改了 nonceSize是负就应该panic xudp是有预检的 就这样吧 有问题再说

@Fangliding Fangliding changed the title Fix func ReadFullFrom size underflow panic DNS: Fix wrong protocol parse Oct 16, 2025
@RPRX RPRX merged commit 27ad487 into XTLS:main Nov 21, 2025
39 checks passed
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