Copilot commented on code in PR #3859:
URL: https://github.com/apache/avro/pull/3859#discussion_r3567558879


##########
lang/c++/include/avro/GenericDatum.hh:
##########
@@ -244,6 +244,9 @@ public:
      * \param branch The index for the selected branch.
      */
     void selectBranch(size_t branch) {
+        if (branch >= schema()->leaves()) {
+            throw Exception("Union branch index out of range: must be less 
than " + std::to_string(schema()->leaves()) + ", but is " + 
std::to_string(branch));
+        }

Review Comment:
   GenericUnion::selectBranch() now guards against out-of-range branch indices, 
but because the parameter is size_t, a negative union index decoded from the 
wire (e.g. BinaryDecoder::decodeUnionIndex() casting an int64_t) will wrap to a 
huge value and produce a confusing error. Consider validating union indices at 
decode time (reject idx < 0 and size_t truncation) so negative inputs fail with 
a clear Avro exception before reaching selectBranch().



-- 
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