Skip to content

Commit 4b38782

Browse files
eveningcafeNgô Quang Hòagaius-qi
authored
fix: handle query params in blob URL regex (#1582)
* fix: handle query params in blob URL regex Fixes #1580 containerd adds ?ns=<registry> query parameter when using registry mirrors. The blob URL regex was capturing this parameter as part of the digest, causing parse failures and breaking P2P distribution. Changed regex from: r"^(.*)://(.*)/v2/(.*)/blobs/(.*)$" to: r"^(.*)://(.*)/v2/(.*)/blobs/([^?]+)(?:\?.*)?$" This excludes query parameters from the digest capture group. * test: add test case for blob URL with query parameters Signed-off-by: Gaius <gaius.qi@gmail.com> * chore(dependencies): update dragonfly-client versions to 1.1.17 Signed-off-by: Gaius <gaius.qi@gmail.com> --------- Signed-off-by: Gaius <gaius.qi@gmail.com> Co-authored-by: Ngô Quang Hòa <hoanq3@vng.com.vn> Co-authored-by: Gaius <gaius.qi@gmail.com>
1 parent a2eca66 commit 4b38782

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ members = [
1313
]
1414

1515
[workspace.package]
16-
version = "1.1.16"
16+
version = "1.1.17"
1717
authors = ["The Dragonfly Developers"]
1818
homepage = "https://d7y.io/"
1919
repository = "https://github.com/dragonflyoss/client.git"
@@ -23,14 +23,14 @@ readme = "README.md"
2323
edition = "2021"
2424

2525
[workspace.dependencies]
26-
dragonfly-client = { path = "dragonfly-client", version = "1.1.16" }
27-
dragonfly-client-core = { path = "dragonfly-client-core", version = "1.1.16" }
28-
dragonfly-client-config = { path = "dragonfly-client-config", version = "1.1.16" }
29-
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "1.1.16" }
30-
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "1.1.16" }
31-
dragonfly-client-metric = { path = "dragonfly-client-metric", version = "1.1.16" }
32-
dragonfly-client-util = { path = "dragonfly-client-util", version = "1.1.16" }
33-
dragonfly-client-init = { path = "dragonfly-client-init", version = "1.1.16" }
26+
dragonfly-client = { path = "dragonfly-client", version = "1.1.17" }
27+
dragonfly-client-core = { path = "dragonfly-client-core", version = "1.1.17" }
28+
dragonfly-client-config = { path = "dragonfly-client-config", version = "1.1.17" }
29+
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "1.1.17" }
30+
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "1.1.17" }
31+
dragonfly-client-metric = { path = "dragonfly-client-metric", version = "1.1.17" }
32+
dragonfly-client-util = { path = "dragonfly-client-util", version = "1.1.17" }
33+
dragonfly-client-init = { path = "dragonfly-client-init", version = "1.1.17" }
3434
dragonfly-api = "=2.2.8"
3535
thiserror = "2.0"
3636
futures = "0.3.31"

dragonfly-client-util/src/digest/mod.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub const SEPARATOR: &str = ":";
2929

3030
lazy_static! {
3131
/// BLOB_URL_REGEX is the regex for oci blob url, e.g. http(s)://<registry>/v2/<repository>/blobs/<digest>.
32-
static ref BLOB_URL_REGEX: Regex = Regex::new(r"^(.*)://(.*)/v2/(.*)/blobs/(.*)$").unwrap();
32+
static ref BLOB_URL_REGEX: Regex = Regex::new(r"^(.*)://(.*)/v2/(.*)/blobs/([^?]+)(?:\?.*)?$").unwrap();
3333
}
3434

3535
/// is_blob_url checks if the url is an oci blob url.
@@ -262,6 +262,26 @@ mod tests {
262262
"b2c366cce7e68013d5441c6326d5a3e1b12aeb5ed58564d0fd3fa089bc29cb6e"
263263
);
264264

265+
let url = "https://index.docker.io/v2/library/alpine/blobs/sha256:b2c366cce7e68013d5441c6326d5a3e1b12aeb5ed58564d0fd3fa089bc29cb6e?ns=docker.io";
266+
let digest = Digest::extract_from_blob_url(url);
267+
assert!(digest.is_some());
268+
let digest = digest.unwrap();
269+
assert_eq!(digest.algorithm(), Algorithm::Sha256);
270+
assert_eq!(
271+
digest.encoded(),
272+
"b2c366cce7e68013d5441c6326d5a3e1b12aeb5ed58564d0fd3fa089bc29cb6e"
273+
);
274+
275+
let url = "http://localhost:5000/v2/myrepo/blobs/sha256:b2c366cce7e68013d5441c6326d5a3e1b12aeb5ed58564d0fd3fa089bc29cb6e?id=12345";
276+
let digest = Digest::extract_from_blob_url(url);
277+
assert!(digest.is_some());
278+
let digest = digest.unwrap();
279+
assert_eq!(digest.algorithm(), Algorithm::Sha256);
280+
assert_eq!(
281+
digest.encoded(),
282+
"b2c366cce7e68013d5441c6326d5a3e1b12aeb5ed58564d0fd3fa089bc29cb6e"
283+
);
284+
265285
let invalid_urls = vec![
266286
"http://registry.example.com/blobs/sha256:abc",
267287
"http://registry.example.com/v2/repo/manifests/sha256:abc",

0 commit comments

Comments
 (0)