Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

时间encode越界 #348

Closed
Penglq opened this issue Feb 9, 2023 · 7 comments · Fixed by #352
Closed

时间encode越界 #348

Penglq opened this issue Feb 9, 2023 · 7 comments · Fixed by #352

Comments

@Penglq
Copy link

Penglq commented Feb 9, 2023

What happened:
dubbo-go一个原始日期为:2296-11-23 16:09:26.311 的值,java那边收到的是另一个值,是因为hessian的类型不对导致越界了吗
What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

@Penglq
Copy link
Author

Penglq commented Feb 9, 2023

是time.UnixNano int64类型越界,如果使用time;当时开发的时候go版本不高,在encode为ms时间戳时,只有time.Unix和UnixNano,Unix()会丢失ms精度,能支持到2262年,所以用的UnixNano()/1e6。

可以先看看业务上是不是可以把这个值缩小,如果是过期时间/封禁时间的话 可以考虑一下

@tiltwind
Copy link
Contributor

tiltwind commented Feb 9, 2023

@Penglq can u submit a unit test to simulate the unexpected case, ref

testJavaDecode(t, "argDate_0", time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC))

@Penglq
Copy link
Author

Penglq commented Feb 16, 2023

image

@tiltwind
Copy link
Contributor

tiltwind commented Feb 17, 2023

@Penglq the hessian2 uses the api time.UnixNano(), but the year 2914 overflows for int64 for nanoseconds.
From golang 1.17, it supports time.UnixMilli() api, which will fix this issue. (see golang/go#44196)

But now the go version of the hessian ci used is 1.13, maybe we needs to upgrade the go version now.
How do u think?@AlexStocks

// UnixNano returns t as a Unix time, the number of nanoseconds elapsed
// since January 1, 1970 UTC. The result is undefined if the Unix time
// in nanoseconds cannot be represented by an int64 (a date before the year
// 1678 or after 2262). Note that this means the result of calling UnixNano
// on the zero Time is undefined. The result does not depend on the
// location associated with t.
func (t Time) UnixNano() int64 {
	return (t.unixSec())*1e9 + int64(t.nsec())
}

@tiltwind
Copy link
Contributor

@ilaotan
Copy link

ilaotan commented Feb 23, 2023

支持升版本

wongoo pushed a commit to wongoo/hessian2 that referenced this issue Feb 24, 2023
wongoo pushed a commit that referenced this issue Feb 24, 2023
wongoo pushed a commit that referenced this issue Feb 24, 2023
* mark array types deprecated (#347)

* mark array types deprected

* mark array types deprecated

* Update README.md

change readme title

* upgrade go to v1.17 to fix issue #348

---------

Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
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 a pull request may close this issue.

3 participants