| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -2607,6 +2607,92 @@ mod _io { | |
| } | ||
| } | ||
|
|
||
| #[pyclass(module = "_io", name, no_attr)] | ||
| #[derive(Debug, PyPayload)] | ||
| struct StatelessIncrementalEncoder { | ||
| encode: PyObjectRef, | ||
| errors: Option<PyStrRef>, | ||
| name: Option<PyStrRef>, | ||
| } | ||
|
|
||
| #[pyclass] | ||
| impl StatelessIncrementalEncoder { | ||
| #[pymethod] | ||
| fn encode( | ||
| &self, | ||
| input: PyObjectRef, | ||
| _final: OptionalArg<bool>, | ||
| vm: &VirtualMachine, | ||
| ) -> PyResult { | ||
| let mut args: Vec<PyObjectRef> = vec![input]; | ||
| if let Some(errors) = &self.errors { | ||
| args.push(errors.to_owned().into()); | ||
| } | ||
| let res = self.encode.call(args, vm)?; | ||
| let tuple: PyTupleRef = res.try_into_value(vm)?; | ||
| if tuple.len() != 2 { | ||
| return Err(vm.new_type_error("encoder must return a tuple (object, integer)")); | ||
| } | ||
| Ok(tuple[0].clone()) | ||
| } | ||
|
|
||
| #[pymethod] | ||
| fn reset(&self) {} | ||
|
|
||
| #[pymethod] | ||
| fn setstate(&self, _state: PyObjectRef) {} | ||
|
|
||
| #[pymethod] | ||
| fn getstate(&self, vm: &VirtualMachine) -> PyObjectRef { | ||
| vm.ctx.new_int(0).into() | ||
| } | ||
|
|
||
| #[pygetset] | ||
| fn name(&self) -> Option<PyStrRef> { | ||
| self.name.clone() | ||
| } | ||
| } | ||
|
|
||
| #[pyclass(module = "_io", name, no_attr)] | ||
| #[derive(Debug, PyPayload)] | ||
| struct StatelessIncrementalDecoder { | ||
| decode: PyObjectRef, | ||
| errors: Option<PyStrRef>, | ||
| } | ||
|
|
||
| #[pyclass] | ||
| impl StatelessIncrementalDecoder { | ||
| #[pymethod] | ||
| fn decode( | ||
| &self, | ||
| input: PyObjectRef, | ||
| _final: OptionalArg<bool>, | ||
| vm: &VirtualMachine, | ||
| ) -> PyResult { | ||
| let mut args: Vec<PyObjectRef> = vec![input]; | ||
| if let Some(errors) = &self.errors { | ||
| args.push(errors.to_owned().into()); | ||
| } | ||
| let res = self.decode.call(args, vm)?; | ||
| let tuple: PyTupleRef = res.try_into_value(vm)?; | ||
| if tuple.len() != 2 { | ||
| return Err(vm.new_type_error("decoder must return a tuple (object, integer)")); | ||
| } | ||
| Ok(tuple[0].clone()) | ||
| } | ||
|
|
||
| #[pymethod] | ||
| fn getstate(&self, vm: &VirtualMachine) -> (PyBytesRef, u64) { | ||
| (vm.ctx.empty_bytes.to_owned(), 0) | ||
| } | ||
|
|
||
| #[pymethod] | ||
| fn setstate(&self, _state: PyTupleRef, _vm: &VirtualMachine) {} | ||
|
|
||
| #[pymethod] | ||
| fn reset(&self) {} | ||
| } | ||
|
Comment thread
Comment on lines
+2656
to
+2694
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality⚠️ Potential issue | 🟡 Minor Validate the consumed-length element from codec output. Same concern as the encoder wrapper: the second tuple element should be an integer; otherwise invalid codec implementations pass silently. 🛠️ Suggested guard for the consumed-length slot let tuple: PyTupleRef = res.try_into_value(vm)?;
if tuple.len() != 2 {
return Err(vm.new_type_error("decoder must return a tuple (object, integer)"));
}
+ let _consumed: isize = isize::try_from_object(vm, tuple[1].clone()).map_err(|_| {
+ vm.new_type_error("decoder must return a tuple (object, integer)")
+ })?;
Ok(tuple[0].clone())Verify each finding against the current code and only fix it if needed.
In `@crates/vm/src/stdlib/io.rs` around lines 2656 - 2694, In
StatelessIncrementalDecoder::decode, validate that the second tuple element is
an integer and raise a TypeError if not; after converting res to PyTupleRef and
checking tuple.len(), try to convert tuple[1] to an integer (using the VM's
integer/index conversion helpers) and return Err(vm.new_type_error("decoder must
return a tuple (object, integer)")) when conversion fails, otherwise proceed to
return tuple[0].clone() as before. Ensure this check is applied in the decode
method to mirror the encoder wrapper's guard.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| #[pyattr] | ||
| #[pyclass(name = "TextIOWrapper", base = _TextIOBase)] | ||
| #[derive(Debug, Default)] | ||
| Expand Down Expand Up | @@ -2830,7 +2916,25 @@ mod _io { | |
|
|
||
| let encoder = if vm.call_method(buffer, "writable", ())?.try_to_bool(vm)? { | ||
| let incremental_encoder = | ||
| codec.get_incremental_encoder(Some(errors.to_owned()), vm)?; | ||
| match codec.get_incremental_encoder(Some(errors.to_owned()), vm) { | ||
| Ok(encoder) => encoder, | ||
| Err(err) | ||
| if err.fast_isinstance(vm.ctx.exceptions.type_error) | ||
| || err.fast_isinstance(vm.ctx.exceptions.attribute_error) => | ||
| { | ||
| let name = vm | ||
| .get_attribute_opt(codec.as_tuple().to_owned().into(), "name")? | ||
| .and_then(|obj| obj.downcast::<PyStr>().ok()); | ||
| StatelessIncrementalEncoder { | ||
| encode: codec.get_encode_func().to_owned(), | ||
| errors: Some(errors.to_owned()), | ||
| name, | ||
| } | ||
| .into_ref(&vm.ctx) | ||
| .into() | ||
| } | ||
| Err(err) => return Err(err), | ||
| }; | ||
| let encoding_name = vm.get_attribute_opt(incremental_encoder.clone(), "name")?; | ||
| let encode_func = encoding_name.and_then(|name| { | ||
| let name = name.downcast_ref::<PyStr>()?; | ||
| Expand All | @@ -2845,7 +2949,21 @@ mod _io { | |
| }; | ||
|
|
||
| let decoder = if vm.call_method(buffer, "readable", ())?.try_to_bool(vm)? { | ||
| let decoder = codec.get_incremental_decoder(Some(errors.to_owned()), vm)?; | ||
| let decoder = match codec.get_incremental_decoder(Some(errors.to_owned()), vm) { | ||
| Ok(decoder) => decoder, | ||
| Err(err) | ||
| if err.fast_isinstance(vm.ctx.exceptions.type_error) | ||
| || err.fast_isinstance(vm.ctx.exceptions.attribute_error) => | ||
| { | ||
| StatelessIncrementalDecoder { | ||
| decode: codec.get_decode_func().to_owned(), | ||
| errors: Some(errors.to_owned()), | ||
| } | ||
| .into_ref(&vm.ctx) | ||
| .into() | ||
| } | ||
| Err(err) => return Err(err), | ||
| }; | ||
| if let Newlines::Universal | Newlines::Passthrough = newline { | ||
| let args = IncrementalNewlineDecoderArgs { | ||
| decoder, | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality⚠️ Potential issue | 🟡 Minor
Validate the consumed-length element from codec output.
The wrapper ignores the second tuple item entirely; if it’s not an integer, malformed codecs won’t surface errors. Consider validating it to match the codec contract.
🛠️ Suggested guard for the consumed-length slotlet tuple: PyTupleRef = res.try_into_value(vm)?; if tuple.len() != 2 { return Err(vm.new_type_error("encoder must return a tuple (object, integer)")); } + let _consumed: isize = isize::try_from_object(vm, tuple[1].clone()).map_err(|_| { + vm.new_type_error("encoder must return a tuple (object, integer)") + })?; Ok(tuple[0].clone())Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.