-
Notifications
You must be signed in to change notification settings - Fork 2
check the layer media type before flashing #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bennyz
wants to merge
3
commits into
jumpstarter-dev:main
Choose a base branch
from
bennyz:fix-layer-selection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−8
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_typematch. 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mangelajo, thanks for the confirmation! The fix is straightforward — every successful return path inget_single_layerneeds to validate the layer's media type against the flashable disk prefix. Here's the suggested update:Key changes vs the current PR:
media_typedoesn't start withapplication/vnd.automotive.disk.artifact_typepath: the closure additionally requiresis_flashable, so a matching artifact type alone is not enough.is_flashableclosure for consistency.Would you like me to open this as a plan for code changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ab866a4. All three return paths in
get_single_layer()now validate the media type using a sharedis_flashableclosure that checks for theapplication/vnd.automotive.diskprefix:media_type == artifact_typeANDis_flashableis_flashableclosure (functionally unchanged, just refactored for consistency)Also added unit tests covering: single flashable layer acceptance, single non-disk layer rejection, artifact_type-based selection, and no-match error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — but with an important design adjustment:
get_single_layer()is shared between the flash and extract paths. The extraction path (extract_files_from_oci_image_to_dir) legitimately needs to work with non-disk media types (e.g.tar+gziplayers), so adding flashable validation insideget_single_layer()broke the 5oci_extractintegration tests.The fix instead:
get_single_layer()generic — single-layer manifests return the layer directly (callers decide what's valid)flash_from_oci()— the flash-specific path now rejects layers that don't start withapplication/vnd.automotive.diskartifact_typematch, then falls back to the first disk image layerAlso fixed the
&&layerclippy lint (needless borrow).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.