Copilot commented on code in PR #3594:
URL: https://github.com/apache/thrift/pull/3594#discussion_r3547263133


##########
lib/py/src/ext/module.cpp:
##########
@@ -139,11 +139,36 @@ static PyObject* decode_compact(PyObject*, PyObject* 
args) {
   return decode_impl<CompactProtocol>(args);
 }
 
+static PyObject* decode_binary_from_bytes(PyObject*, PyObject* args) {
+  PyObject* bytes_obj = nullptr;
+  PyObject* typeargs = nullptr;
+  if (!PyArg_ParseTuple(args, "OO", &bytes_obj, &typeargs)) {
+    return nullptr;
+  }
+  if (!PyBytes_Check(bytes_obj)) {
+    PyErr_SetString(PyExc_TypeError, "first argument must be bytes");
+    return nullptr;
+  }
+
+  StructTypeArgs parsedargs;
+  if (!parse_struct_args(&parsedargs, typeargs)) {
+    return nullptr;
+  }
+
+  BinaryProtocol protocol;
+  if (!protocol.prepareDecodeBufferFromBytes(bytes_obj)) {
+    return nullptr;
+  }
+
+  return protocol.readStruct(Py_None, parsedargs.klass, parsedargs.spec);
+}

Review Comment:
   `decode_binary_from_bytes` initializes `BinaryProtocol` with default 
string/container length limits (INT32_MAX) and does not provide any way to 
apply the per-protocol `string_length_limit` / `container_length_limit` that 
`decode_binary` honors. Callers that rely on non-default limits will silently 
lose that protection when switching to this API.
   
   Consider accepting optional numeric limit arguments (defaulting to 
INT32_MAX) and applying them via `protocol.setStringLengthLimit(...)` / 
`setContainerLengthLimit(...)` before decoding.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to