You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "gty404 (via GitHub)" <gi...@apache.org> on 2026/10/19 12:21:34 UTC

[PR] fix(arrow): use FULL nanoarrow validation in ProjectBatch [iceberg-cpp]

gty404 opened a new pull request, #1043:
URL: https://github.com/apache/iceberg-cpp/pull/1043

   ## Summary
   - `ProjectBatchNanoarrow` validated incoming batches at `NANOARROW_VALIDATION_LEVEL_DEFAULT` before using `ArrowArrayViewGet{String,Bytes}Unsafe` and raw list/map offset arithmetic per row. nanoarrow documents these `Unsafe` accessors as memory-safe only after `FULL` validation: `DEFAULT` only checks the first/last offsets, not that every intermediate offset is non-decreasing and in-bounds.
   - A non-monotonic intermediate offset can produce a negative size that overflows to a huge `size_t` in the append path, or an out-of-range offset whose bytes get copied into the returned output batch.
   - Raise the validation level to `NANOARROW_VALIDATION_LEVEL_FULL`, matching what `manifest_reader.cc` already does for the same untrusted-batch boundary, closing the inconsistency between the two call sites.
   
   ## Test plan
   - Added `ProjectBatchTest.RejectsNonMonotonicStringOffsets`, which hand-assembles (via the nanoarrow C ABI, since Arrow's builders always emit monotonic offsets) a string array with offsets `[0, 5, 2]`: the first/last offsets are consistent with the 2-byte data buffer, so `DEFAULT` validation accepts it, but `FULL` validation correctly rejects it as non-monotonic.
   - Verified the new test fails without the fix (stashed the one-line change, rebuilt, confirmed `ProjectBatch` returned a value instead of an error) and passes with it.
   - `./src/iceberg/test/data_test` — 103/103 passed.
   - `pre-commit run` on the changed files — passed.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] fix(arrow): use FULL nanoarrow validation in ProjectBatch [iceberg-cpp]

Posted by "gty404 (via GitHub)" <gi...@apache.org>.
gty404 commented on code in PR #1043:
URL: https://github.com/apache/iceberg-cpp/pull/1043#discussion_r4332445581


##########
src/iceberg/arrow_c_data_util.cc:
##########
@@ -341,8 +341,14 @@ Result<ArrowArray> ProjectBatchNanoarrow(
   internal::ArrowArrayViewGuard input_view_guard(&input_view);
   ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(
       ArrowArrayViewSetArray(&input_view, &input_batch, &error), error);
+  // FULL validation is required here: the append path below uses
+  // ArrowArrayViewGet{String,Bytes}Unsafe and raw list/map offset arithmetic,
+  // which nanoarrow only documents as memory-safe after FULL validation
+  // (DEFAULT does not check that every offsets-buffer entry is non-decreasing
+  // and in-bounds). This matches the FULL validation already performed on the
+  // equivalent untrusted-batch boundary in manifest_reader.cc.
   ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(
-      ArrowArrayViewValidate(&input_view, NANOARROW_VALIDATION_LEVEL_DEFAULT, &error),
+      ArrowArrayViewValidate(&input_view, NANOARROW_VALIDATION_LEVEL_FULL, &error),

Review Comment:
   Good catch, the cost is real but small in absolute terms. I benchmarked ProjectBatch (nanoarrow path) on a 50k-row batch (int32 + string column) with DEFAULT vs FULL validation, averaged over 200 runs:
   
   | selectivity | DEFAULT | FULL | overhead |
   |---|---|---|---|
   | 100% rows alive | ~4074 us/batch | ~4219 us/batch | +3.6% |
   | 1% rows alive (heavy delete filtering) | ~44.5 us/batch | ~82.2 us/batch | +85% (~1.85x) |
   
   So in the worst case (most rows filtered out by deletes, which is exactly where the row-append cost no longer dominates), FULL validation roughly doubles this step's time - but the absolute delta is ~38us for a 50k-row batch (~0.75ns/row), which should be negligible next to I/O/decode for a real scan.
   
   Given nanoarrow has no bounds-checked "safe" counterpart to `ArrowArrayViewGetStringUnsafe`/`GetBytesUnsafe` in this pinned version, FULL batch-level validation is the only way to satisfy contract today. @wgtmac curious for your take: keep this as-is given the cost is small and bounded, or is there a reason to treat the in-tree reader path differently (e.g. skip FULL validation when the batch is known to come from our own Avro/Parquet readers)?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] fix(arrow): make full batch validation configurable [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac merged PR #1043:
URL: https://github.com/apache/iceberg-cpp/pull/1043


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] fix(arrow): use FULL nanoarrow validation in ProjectBatch [iceberg-cpp]

Posted by "gty404 (via GitHub)" <gi...@apache.org>.
gty404 commented on code in PR #1043:
URL: https://github.com/apache/iceberg-cpp/pull/1043#discussion_r4332445581


##########
src/iceberg/arrow_c_data_util.cc:
##########
@@ -341,8 +341,14 @@ Result<ArrowArray> ProjectBatchNanoarrow(
   internal::ArrowArrayViewGuard input_view_guard(&input_view);
   ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(
       ArrowArrayViewSetArray(&input_view, &input_batch, &error), error);
+  // FULL validation is required here: the append path below uses
+  // ArrowArrayViewGet{String,Bytes}Unsafe and raw list/map offset arithmetic,
+  // which nanoarrow only documents as memory-safe after FULL validation
+  // (DEFAULT does not check that every offsets-buffer entry is non-decreasing
+  // and in-bounds). This matches the FULL validation already performed on the
+  // equivalent untrusted-batch boundary in manifest_reader.cc.
   ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(
-      ArrowArrayViewValidate(&input_view, NANOARROW_VALIDATION_LEVEL_DEFAULT, &error),
+      ArrowArrayViewValidate(&input_view, NANOARROW_VALIDATION_LEVEL_FULL, &error),

Review Comment:
   Good catch, the cost is real but small in absolute terms. I benchmarked ProjectBatch (nanoarrow path) on a 50k-row batch (int32 + string column) with DEFAULT vs FULL validation, averaged over 200 runs:
   
   | selectivity | DEFAULT | FULL | overhead |
   |---|---|---|---|
   | 100% rows alive | ~4074 us/batch | ~4219 us/batch | +3.6% |
   | 1% rows alive (heavy delete filtering) | ~44.5 us/batch | ~82.2 us/batch | +85% (~1.85x) |
   
   So in the worst case (most rows filtered out by deletes, which is exactly where the row-append cost no longer dominates), FULL validation roughly doubles this step's time - but the absolute delta is ~38us for a 50k-row batch (~0.75ns/row), which should be negligible next to I/O/decode for a real scan.
   
   Given nanoarrow has no bounds-checked "safe" counterpart to `ArrowArrayViewGetStringUnsafe`/`GetBytesUnsafe` in this pinned version, FULL batch-level validation is the only way to satisfy their documented safety contract today. @wgtmac curious for your take: keep this as-is given the cost is small and bounded, or is there a reason to treat the in-tree reader path differently (e.g. skip FULL validation when the batch is known to come from our own Avro/Parquet readers)?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] fix(arrow): use FULL nanoarrow validation in ProjectBatch [iceberg-cpp]

Posted by "shangxinli (via GitHub)" <gi...@apache.org>.
shangxinli commented on code in PR #1043:
URL: https://github.com/apache/iceberg-cpp/pull/1043#discussion_r4328471692


##########
src/iceberg/arrow_c_data_util.cc:
##########
@@ -341,8 +341,14 @@ Result<ArrowArray> ProjectBatchNanoarrow(
   internal::ArrowArrayViewGuard input_view_guard(&input_view);
   ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(
       ArrowArrayViewSetArray(&input_view, &input_batch, &error), error);
+  // FULL validation is required here: the append path below uses
+  // ArrowArrayViewGet{String,Bytes}Unsafe and raw list/map offset arithmetic,
+  // which nanoarrow only documents as memory-safe after FULL validation
+  // (DEFAULT does not check that every offsets-buffer entry is non-decreasing
+  // and in-bounds). This matches the FULL validation already performed on the
+  // equivalent untrusted-batch boundary in manifest_reader.cc.
   ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(
-      ArrowArrayViewValidate(&input_view, NANOARROW_VALIDATION_LEVEL_DEFAULT, &error),
+      ArrowArrayViewValidate(&input_view, NANOARROW_VALIDATION_LEVEL_FULL, &error),

Review Comment:
   ProjectBatch runs per batch on the scan path via file_scan_task_reader.cc:118, so FULL validation now walks every offsets buffer on every batch. Unlike the manifest_reader case these come from our own readers - is that cost intended?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] fix(arrow): make full batch validation configurable [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #1043:
URL: https://github.com/apache/iceberg-cpp/pull/1043#discussion_r4421803285


##########
src/iceberg/arrow_validation.h:
##########
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include <cstdint>
+
+namespace iceberg {
+
+/// Validation policy for Arrow arrays before accessing their contents.
+enum class ArrowValidationMode : uint8_t {

Review Comment:
   TBH, I don't believe this enum is worth a separate header file. I know that the reason is the dependency from FileScanTaskReader. Perhaps we can use a key-value property to work around this which might be more flexible.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] fix(arrow): make full batch validation configurable [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #1043:
URL: https://github.com/apache/iceberg-cpp/pull/1043#discussion_r4421797571


##########
src/iceberg/arrow_c_data_util.cc:
##########
@@ -341,8 +341,14 @@ Result<ArrowArray> ProjectBatchNanoarrow(
   internal::ArrowArrayViewGuard input_view_guard(&input_view);
   ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(
       ArrowArrayViewSetArray(&input_view, &input_batch, &error), error);
+  // FULL validation is required here: the append path below uses
+  // ArrowArrayViewGet{String,Bytes}Unsafe and raw list/map offset arithmetic,
+  // which nanoarrow only documents as memory-safe after FULL validation
+  // (DEFAULT does not check that every offsets-buffer entry is non-decreasing
+  // and in-bounds). This matches the FULL validation already performed on the
+  // equivalent untrusted-batch boundary in manifest_reader.cc.
   ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(
-      ArrowArrayViewValidate(&input_view, NANOARROW_VALIDATION_LEVEL_DEFAULT, &error),
+      ArrowArrayViewValidate(&input_view, NANOARROW_VALIDATION_LEVEL_FULL, &error),

Review Comment:
   I agree that we shouldn't enable full validation by default.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org