Skip to content

Commit cbdbe27

Browse files
author
Roy Lin
committed
fix(cri): reject empty image reference in pull/status/remove image
PullImage, ImageStatus and RemoveImage validated that the image SPEC was present but not that image_spec.image was non-empty. An empty reference passed the check and failed deep in reference parsing with a confusing error. Reject it up front with a clear invalid_argument, consistently across the three image RPCs. From the CRI audit (hand-verified). clippy -D warnings clean; 237 cri tests pass.
1 parent 32ca2be commit cbdbe27

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/cri/src/image_service.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ impl ImageService for BoxImageService {
225225
let image_spec = req
226226
.image
227227
.ok_or_else(|| Status::invalid_argument("image spec required"))?;
228+
if image_spec.image.trim().is_empty() {
229+
// Reject an empty reference up front; otherwise it fails deep in
230+
// reference parsing with a confusing error.
231+
return Err(Status::invalid_argument(
232+
"image reference must not be empty",
233+
));
234+
}
228235

229236
let digest = self.resolve_digest(&image_spec.image).await;
230237

@@ -258,6 +265,13 @@ impl ImageService for BoxImageService {
258265
let image_spec = req
259266
.image
260267
.ok_or_else(|| Status::invalid_argument("image spec required"))?;
268+
if image_spec.image.trim().is_empty() {
269+
// Reject an empty reference up front; otherwise it fails deep in
270+
// reference parsing with a confusing error.
271+
return Err(Status::invalid_argument(
272+
"image reference must not be empty",
273+
));
274+
}
261275

262276
// Honor kubelet's per-request credentials (imagePullSecrets). When the
263277
// request carries usable auth, pull with a one-off puller built from it;
@@ -298,6 +312,13 @@ impl ImageService for BoxImageService {
298312
let image_spec = req
299313
.image
300314
.ok_or_else(|| Status::invalid_argument("image spec required"))?;
315+
if image_spec.image.trim().is_empty() {
316+
// Reject an empty reference up front; otherwise it fails deep in
317+
// reference parsing with a confusing error.
318+
return Err(Status::invalid_argument(
319+
"image reference must not be empty",
320+
));
321+
}
301322

302323
tracing::info!(image = %image_spec.image, "CRI RemoveImage");
303324

0 commit comments

Comments
 (0)