Skip to content

fix(modelscope): validate ranged responses#1933

Open
NelZyhh wants to merge 2 commits into
dragonflyoss:mainfrom
NelZyhh:fix/dfget-ms
Open

fix(modelscope): validate ranged responses#1933
NelZyhh wants to merge 2 commits into
dragonflyoss:mainfrom
NelZyhh:fix/dfget-ms

Conversation

@NelZyhh

@NelZyhh NelZyhh commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Related Issue

Summary

  • add strict validation for ranged responses in the ModelScope backend
  • reject ranged downloads unless the source returns 206 Partial Content
  • verify Content-Range exists and matches the requested byte interval
  • return backend failure instead of silently writing incorrect piece content
  • add a regression test for the 200 OK + full body case on range requests

Background

When downloading modelscope:// files by pieces, the client previously treated any 2xx response as success.
If a ranged request unexpectedly returned a full body response, the client could still write the first N bytes to a non-zero offset.
This could produce files with the correct size but corrupted content.

A real reproduction showed:

  • piece 0 content and offset 4194304 content were identical
  • source file size matched, but file body was corrupted

Root Cause

The ModelScope backend propagated the Range request header, but it did not validate:

  • response status is 206 Partial Content
  • Content-Range header is present
  • Content-Range start/end matches the requested range

As a result, an invalid ranged response could pass through as a successful piece download.

Changes

  • add validate_range_response() in dragonfly-client-backend/src/model_scope.rs
  • require 206 Partial Content for ranged requests
  • require valid Content-Range for ranged requests
  • mark the backend response as failed when range validation fails
  • update the existing range success test to include Content-Range
  • add a regression test that rejects 200 OK + full body for a range request

Testing

  • passed: cargo fmt --check
  • added: range success test with valid Content-Range
  • added: regression test for 200 OK + full body
  • note: local cargo check --all --all-targets and cargo clippy --all-targets -- -D warnings were blocked earlier by a broken local Rust 1.88.0 toolchain; the toolchain has been repaired and the full checks are being rerun

Signed-off-by: zhangyh66 <zhangyh66@chinatelecom.cn>
@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.13986% with 57 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.26%. Comparing base (a4a57d6) to head (775d1cf).

Files with missing lines Patch % Lines
dragonfly-client-backend/src/model_scope.rs 60.13% 57 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1933      +/-   ##
==========================================
+ Coverage   47.21%   47.26%   +0.05%     
==========================================
  Files          94       94              
  Lines       24214    24356     +142     
==========================================
+ Hits        11432    11512      +80     
- Misses      12782    12844      +62     
Files with missing lines Coverage Δ
dragonfly-client-backend/src/model_scope.rs 76.54% <60.13%> (-5.81%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: zhangyh66 <zhangyh66@chinatelecom.cn>
@gaius-qi gaius-qi added the enhancement New feature or request label Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants