Copilot commented on code in PR #3859:
URL: https://github.com/apache/avro/pull/3859#discussion_r3565707861
##########
lang/c++/impl/Generic.cc:
##########
@@ -25,6 +26,86 @@ using std::ostringstream;
using std::string;
using std::vector;
+// Minimum number of bytes a single value of the given schema node can occupy
on
+// the wire. Used to reject an array/map block count that could not be backed
by
+// the bytes remaining. A type that can encode to zero bytes (null) returns 0,
+// which disables the collection check for it (so an array of nulls is not
+// falsely rejected). A depth limit breaks self-referencing (symbolic) schemas.
+static int64_t minBytesPerElement(const NodePtr &node, int depth) {
+ if (!node) {
+ return 0;
+ }
+ if (depth > 64) {
+ // A cyclic or pathologically deep schema. Return 1 (not 0) so the
+ // collection check stays enabled rather than being silently bypassed;
+ // a valid recursive value always encodes to at least 1 byte.
+ return 1;
+ }
Review Comment:
minBytesPerElement() applies the depth limit before checking the node type.
That means a deeply nested AVRO_NULL schema (depth > 64) will return 1 instead
of 0, incorrectly enabling the collection-availability check and potentially
rejecting valid data for zero-byte element types nested under deep schemas
(e.g., records chaining down to null). Consider preserving the AVRO_NULL == 0
behavior even when the depth cutoff is hit.
--
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]