Skip to content

fix(ota): avoid writing Ymodem padding beyond firmware size#24

Open
wdfk-prog wants to merge 1 commit intoRT-Thread-packages:masterfrom
wdfk-prog:padding
Open

fix(ota): avoid writing Ymodem padding beyond firmware size#24
wdfk-prog wants to merge 1 commit intoRT-Thread-packages:masterfrom
wdfk-prog:padding

Conversation

@wdfk-prog
Copy link

@wdfk-prog wdfk-prog commented Jan 18, 2026

为什么提交这份PR (why to submit this PR)

  • 问题 / 动机:
    • Ymodem 传输在最后一个数据包可能会带有 padding 字节(0X1A)。当前实现会把接收到的整个 block 全量写入 DL 分区,
      可能导致在固件尾部追加非固件数据(padding),进而引发固件校验失败(CRC/签名)或启动异常。
  • 影响范围:
    • 影响通过 Ymodem 进行 OTA 下载的流程,以及写入到 DL 分区的固件完整性。
  • 关联信息:
    • N/A

你的解决方案是什么 (what is your solution)

  • 方案思路:
    • 基于固件声明的总大小(update_file_total_size)对每次写入进行截断,只写入剩余的真实固件字节,
      超出部分视为 Ymodem padding 并跳过。
  • 关键改动:
    • 当 update_file_cur_size >= update_file_total_size 时,直接返回 ACK,不再写分区。
    • 计算 remaining = total - cur,写入长度 write_len = min(len, remaining)。
    • update_file_cur_size 按实际写入的 write_len 进行累加。
  • 兼容性 / 风险:
    • 风险较低。对非 padding 的正常数据块行为不变;仅在传输末尾避免额外字节写入,从而提升固件数据一致性。
  • 回滚方案(可选):
    • 可直接 revert 本提交恢复原行为。

测试 (Testing)

  • 测试环境:
    • 板卡 / 设备:<填写你的板卡>
    • OS / FW / 版本:<填写版本信息>
  • 测试用例:
    • 固件大小非 block 对齐的 Ymodem OTA(确认末尾 padding 不会被写入)
    • 固件大小 block 对齐的 Ymodem OTA(回归验证)
  • 测试结果:
    • <填写 pass/fail 及必要日志>

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced firmware update reliability by preventing writes that exceed intended firmware size, improving boundary handling, and ensuring proper error handling during the update process.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 18, 2026

Walkthrough

The ymodem_on_data function in the firmware OTA module now caps write operations to the remaining firmware size. It computes the remaining bytes (total minus current position), derives the actual write length as the minimum of requested and remaining bytes, and only writes within bounds. This prevents overshooting the firmware size and corrupting padding bytes while maintaining proper error handling.

Changes

Cohort / File(s) Summary
Firmware OTA write boundary handling
src/ymodem_ota.c
Modified ymodem_on_data function to cap writes to remaining firmware size; adds logic to compute remaining bytes, limit write length via min operation, skip writes at boundary, and advance cursor only by actually written bytes; guards against firmware size overshoots.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(ota): avoid writing Ymodem padding beyond firmware size' clearly and specifically describes the main change: preventing Ymodem padding bytes from being written beyond the firmware boundary.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@wdfk-prog
Copy link
Author

wdfk-prog commented Feb 5, 2026

@Guozhanxin @Rbb666

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