Skip to content

Commit 6f9f6b3

Browse files
committed
pyoxidizer: validate attribute name before calling set_attr_add_collection_context()
This prevents a runtime panic due to bad argument validation. Closes #561.
1 parent 739b5f2 commit 6f9f6b3

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

pyoxidizer/docs/pyoxidizer_history.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Bug Fixes
5050
* PyO3 Rust crates upgraded from 0.16.4 to 0.16.5. The upgrade fixes compatibility
5151
issues with Python 3.10 that could lead to runtime crashes or incorrect behavior
5252
in many configurations.
53+
* Fixed a runtime panic when incorrect attribute assignments were attempted on the
54+
``PythonExtensionModule``, ``PythonPackageDistributionResource``, and
55+
``PythonPackageResource`` Starlark types. (#561)
5356

5457
New Features
5558
^^^^^^^^^^^^

pyoxidizer/src/starlark/python_extension_module.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ impl TypedValue for PythonExtensionModuleValue {
133133
}
134134

135135
fn set_attr(&mut self, attribute: &str, value: Value) -> Result<(), ValueError> {
136-
self.set_attr_add_collection_context(attribute, value)
136+
if self.add_collection_context_attrs().contains(&attribute) {
137+
self.set_attr_add_collection_context(attribute, value)
138+
} else {
139+
Err(ValueError::OperationNotSupported {
140+
op: UnsupportedOperation::SetAttr(attribute.to_string()),
141+
left: Self::TYPE.to_owned(),
142+
right: None,
143+
})
144+
}
137145
}
138146
}

pyoxidizer/src/starlark/python_package_distribution_resource.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ impl TypedValue for PythonPackageDistributionResourceValue {
149149
}
150150

151151
fn set_attr(&mut self, attribute: &str, value: Value) -> Result<(), ValueError> {
152-
self.set_attr_add_collection_context(attribute, value)
152+
if self.add_collection_context_attrs().contains(&attribute) {
153+
self.set_attr_add_collection_context(attribute, value)
154+
} else {
155+
Err(ValueError::OperationNotSupported {
156+
op: UnsupportedOperation::SetAttr(attribute.to_string()),
157+
left: Self::TYPE.to_owned(),
158+
right: None,
159+
})
160+
}
153161
}
154162
}

pyoxidizer/src/starlark/python_package_resource.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ impl TypedValue for PythonPackageResourceValue {
145145
}
146146

147147
fn set_attr(&mut self, attribute: &str, value: Value) -> Result<(), ValueError> {
148-
self.set_attr_add_collection_context(attribute, value)
148+
if self.add_collection_context_attrs().contains(&attribute) {
149+
self.set_attr_add_collection_context(attribute, value)
150+
} else {
151+
Err(ValueError::OperationNotSupported {
152+
op: UnsupportedOperation::SetAttr(attribute.to_string()),
153+
left: Self::TYPE.to_owned(),
154+
right: None,
155+
})
156+
}
149157
}
150158
}

pyoxidizer/src/starlark/python_resource.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ pub trait ResourceCollectionContext {
160160
})
161161
}
162162

163+
// The caller should validate that the attribute is an add collection attribute
164+
// before calling. Otherwise a panic can occur.
163165
fn set_attr_add_collection_context(
164166
&mut self,
165167
attribute: &str,

0 commit comments

Comments
 (0)