check the layer media type before flashing#9
check the layer media type before flashing#9bennyz wants to merge 1 commit intojumpstarter-dev:mainfrom
Conversation
To avoid flashing non disk layers we need to check the media type Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com> Assisted-by: claude-sonnet-4.6
📝 WalkthroughWalkthroughModified the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/fls/oci/manifest.rs (1)
67-69: Add direct tests for the new selection rules.A couple of focused unit tests for (1)
artifact_typeselection, (2) single non-disk layer rejection, and (3) the no-match error would cover the new branches inget_single_layer(). The current tests in this file only exercise parsing.Also applies to: 149-168
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/fls/oci/manifest.rs` around lines 67 - 69, Add three focused unit tests for Manifest::get_single_layer covering the new selection branches: (1) create a manifest with artifact_type set and layers such that the correct layer is chosen then assert get_single_layer returns that layer, (2) create a manifest with a single layer whose mediaType is not a disk type and assert get_single_layer returns the expected rejection/error, and (3) create a manifest with no matching layers and assert get_single_layer returns the no-match error. Locate the Manifest struct and the get_single_layer method to construct test Manifests and expected Layer descriptors, use the same error types returned by get_single_layer for assertions, and add these tests adjacent to the existing parsing tests so they exercise lines handling artifact_type and the layer-selection branches.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/fls/oci/manifest.rs`:
- Around line 145-163: The early-return and artifact_type match currently accept
any layer regardless of media_type; update the selection logic in manifest.rs so
every successful path validates the layer.media_type against the allowed
flashable disk types (e.g., check starts_with("application/vnd.automotive.disk")
or an equivalent allowed list) before returning; specifically, when
m.layers.len() == 1 verify m.layers[0].media_type is flashable, when matching
via m.artifact_type ensure the found layer also has a flashable media_type, and
keep the existing fallback that finds the first layer whose media_type
starts_with the disk prefix.
---
Nitpick comments:
In `@src/fls/oci/manifest.rs`:
- Around line 67-69: Add three focused unit tests for Manifest::get_single_layer
covering the new selection branches: (1) create a manifest with artifact_type
set and layers such that the correct layer is chosen then assert
get_single_layer returns that layer, (2) create a manifest with a single layer
whose mediaType is not a disk type and assert get_single_layer returns the
expected rejection/error, and (3) create a manifest with no matching layers and
assert get_single_layer returns the no-match error. Locate the Manifest struct
and the get_single_layer method to construct test Manifests and expected Layer
descriptors, use the same error types returned by get_single_layer for
assertions, and add these tests adjacent to the existing parsing tests so they
exercise lines handling artifact_type and the layer-selection branches.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 55bbc641-f85a-4511-a0be-17bb83c99ad0
📒 Files selected for processing (1)
src/fls/oci/manifest.rs
| if m.layers.len() == 1 { | ||
| return Ok(&m.layers[0]); | ||
| } | ||
|
|
||
| // If artifactType is set, find the layer matching it | ||
| if let Some(ref artifact_type) = m.artifact_type { | ||
| if let Some(layer) = m.layers.iter().find(|l| l.media_type == *artifact_type) { | ||
| return Ok(layer); | ||
| } | ||
| } | ||
|
|
||
| // Fall back to the first disk image layer | ||
| if let Some(layer) = m | ||
| .layers | ||
| .iter() | ||
| .find(|l| l.media_type.starts_with("application/vnd.automotive.disk")) | ||
| { | ||
| return Ok(layer); | ||
| } |
There was a problem hiding this comment.
Validate all successful paths against the flashable media types.
Line 145 returns the only layer before any media-type check, and Lines 149-153 will also accept any artifact_type match. That still lets a non-disk blob through this path, which is exactly what this PR is trying to prevent.
Minimal fix
Manifest::Image(ref m) => {
+ let is_flashable = |layer: &Descriptor| {
+ layer.media_type.starts_with("application/vnd.automotive.disk")
+ };
+
if m.layers.is_empty() {
return Err("Manifest has no layers".to_string());
}
if m.layers.len() == 1 {
- return Ok(&m.layers[0]);
+ let layer = &m.layers[0];
+ return if is_flashable(layer) {
+ Ok(layer)
+ } else {
+ Err(format!("Layer media type '{}' is not flashable", layer.media_type))
+ };
}
// If artifactType is set, find the layer matching it
if let Some(ref artifact_type) = m.artifact_type {
- if let Some(layer) = m.layers.iter().find(|l| l.media_type == *artifact_type) {
+ if let Some(layer) = m.layers.iter().find(|l| {
+ l.media_type == *artifact_type && is_flashable(l)
+ }) {
return Ok(layer);
}
}
// Fall back to the first disk image layer
if let Some(layer) = m
.layers
.iter()
- .find(|l| l.media_type.starts_with("application/vnd.automotive.disk"))
+ .find(|l| is_flashable(l))
{
return Ok(layer);
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/fls/oci/manifest.rs` around lines 145 - 163, The early-return and
artifact_type match currently accept any layer regardless of media_type; update
the selection logic in manifest.rs so every successful path validates the
layer.media_type against the allowed flashable disk types (e.g., check
starts_with("application/vnd.automotive.disk") or an equivalent allowed list)
before returning; specifically, when m.layers.len() == 1 verify
m.layers[0].media_type is flashable, when matching via m.artifact_type ensure
the found layer also has a flashable media_type, and keep the existing fallback
that finds the first layer whose media_type starts_with the disk prefix.
To avoid flashing non disk layers we need to check the media type