Skip to content

fix(common): 修复日期时间戳解析溢出 - #4129

Open
binarywang wants to merge 1 commit into
developfrom
fix/wx-date-type-adapter-overflow
Open

binarywang wants to merge 1 commit into
developfrom
fix/wx-date-type-adapter-overflow

Conversation

@binarywang

Copy link
Copy Markdown
Owner

变更说明

重新提交并完善已关闭的 #4125

  • 使用 JsonReader.nextLong() 读取微信返回的秒级时间戳,支持 2038 年后的时间。
  • 使用 Math.multiplyExact() 将秒转换为毫秒,防止 long 乘法静默溢出。
  • 溢出时抛出带时间戳上下文的 JsonParseException
  • WxDateTypeAdapterTest 加入 TestNG suite,确保 Maven 构建实际执行回归测试。

验证

  • mvn -pl weixin-java-common -am -Dmaven.test.skip=false test
  • Tests run: 24, Failures: 0, Errors: 0, Skipped: 0

Copilot AI lite review requested due to automatic review settings September 21, 2026 03:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-21T03:32:43.831704Z 09bf38d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@augmentcode

augmentcode Bot commented Sep 21, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

摘要:本 PR 修复 weixin-java-common 中秒级时间戳在 2038 年后的解析溢出问题。

变更:

  • 将 `WxDateTypeAdapter` 的数字读取从 `nextInt()` 改为 `nextLong()`,支持更大的秒级时间戳。
  • 使用 `Math.multiplyExact()` 将秒转换为毫秒,并在算术溢出时抛出 `JsonParseException`。
  • 新增 2038 年后时间、正负毫秒溢出及秒级序列化的回归测试。
  • 将新测试加入 TestNG suite,确保 Maven 测试流程会实际执行。

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

return null;
case NUMBER:
return new Date(in.nextInt() * 1000);
long seconds = in.nextLong();

@augmentcode augmentcode Bot Sep 21, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JsonReader.nextLong() 对部分超出 long 范围的数字(如 9223372036854775808)会经 double 回退后饱和为 Long.MAX_VALUE,所以这里最终报出的时间戳是 9223372036854775807,并非原始输入;更大的数值则会直接抛出 NumberFormatException。这使溢出场景的异常类型和“带时间戳上下文”的错误信息不一致,可能误导上游的错误处理和排查。

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

变更范围聚焦且实现与测试覆盖一致,溢出风险已通过 Math.multiplyExact 与回归测试验证并纳入 TestNG suite。

Review effort: Lite
Findings: None

What changed in this PR

该 PR 修复 weixin-java-commonWxDateTypeAdapter 解析微信返回“秒级时间戳”时的 2038+ 与乘法溢出问题,避免因 int/long 溢出导致日期解析错误,并补齐回归测试以确保构建中实际执行。

Changes:

  • 将时间戳读取从 JsonReader.nextInt() 调整为 JsonReader.nextLong(),并用 Math.multiplyExact(seconds, 1000L) 将秒转毫秒,显式捕获溢出。
  • 溢出时抛出包含原始 seconds 值上下文的 JsonParseException(保留 cause)。
  • 新增 WxDateTypeAdapterTest 并加入 TestNG suite,确保 Maven surefire 会运行该回归测试。
File Description
weixin-java-common/​src/​main/​java/​me/​chanjar/​weixin/​common/​util/​json/​WxDateTypeAdapter.java 使用 nextLong + multiplyExact 修复秒级时间戳解析与乘法溢出问题,并在溢出时抛出带上下文的 JsonParseException
weixin-java-common/​src/​test/​java/​me/​chanjar/​weixin/​common/​util/​json/​WxDateTypeAdapterTest.java 新增覆盖 2038+ 时间戳解析、正/负方向溢出拒绝、写出秒级时间戳的回归测试。
weixin-java-common/​src/​test/​resources/​testng.xml WxDateTypeAdapterTest 加入 suite,确保默认 Maven 测试执行覆盖该用例。

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants