Skip to content

Commit c533900

Browse files
fix(safeoutputs): enforce add-build-tag scope for build IDs > i32::MAX (#379)
* fix(safeoutputs): enforce add-build-tag scope for build IDs > i32::MAX Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/dd6d4958-4570-4099-8fcc-bf3d38eb7aa9 Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com> * refactor: simplify u64 cast in add-build-tag scope check Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/dd6d4958-4570-4099-8fcc-bf3d38eb7aa9 Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
1 parent 7575218 commit c533900

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/safeoutputs/add_build_tag.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ impl Executor for AddBuildTagResult {
133133
let config: AddBuildTagConfig = ctx.get_tool_config("add-build-tag");
134134
debug!("Config: {:?}", config);
135135

136-
// 2b. Scope check: by default only the current build can be tagged
136+
// 2b. Scope check: by default only the current build can be tagged.
137+
// Compare in u64 space so that ADO build IDs larger than i32::MAX are
138+
// still enforced (the agent-supplied i32 simply cannot match such
139+
// values, which is the desired behavior).
137140
if !config.allow_any_build {
138-
// Pulled from ctx (sourced from BUILD_BUILDID); narrowed to i32 to
139-
// match the agent-supplied build_id type.
140-
let current_build_id: Option<i32> = ctx
141-
.build_id
142-
.and_then(|id| i32::try_from(id).ok());
143-
if let Some(current_id) = current_build_id {
144-
if self.build_id != current_id {
141+
if let Some(current_id) = ctx.build_id {
142+
// self.build_id is validated > 0, so the cast to u64 is exact;
143+
// values that don't fit in i32 simply cannot match current_id.
144+
if self.build_id as u64 != current_id {
145145
return Ok(ExecutionResult::failure(format!(
146146
"Build #{} cannot be tagged: only the current build (#{}) is \
147147
allowed unless 'allow-any-build: true' is configured",

0 commit comments

Comments
 (0)