This is an automated email from the ASF dual-hosted git repository.

paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git


The following commit(s) were added to refs/heads/main by this push:
     new b7a56dac fix: Return EINVAL from ArrowIpcDecoderDecodeFooter when the 
footer has no schema (#1023)
b7a56dac is described below

commit b7a56dac288d50cadb136bc6ea589132965cb0ff
Author: Shashank Yadav <[email protected]>
AuthorDate: Tue Nov 17 15:05:37 2026 -0700

    fix: Return EINVAL from ArrowIpcDecoderDecodeFooter when the footer has no 
schema (#1023)
    
    Fixes #1022
    
    `ArrowIpcDecoderDecodeFooter()` reads fields from the footer's schema
    table without checking that the footer has one. A footer without the
    optional `schema` field aborts in a Debug build.
    
    This adds the same check that `ArrowIpcDecoderVerifyFooter()` already
    has: when the footer has no schema, it sets the error message "Footer
    has no schema" and returns `EINVAL`. The public header says DecodeFooter
    returns `EINVAL` when the footer cannot be decoded.
    
    Test: adds `NanoarrowIpcTest.NanoarrowIpcFooterMissingSchema` in
    `src/nanoarrow/ipc/decoder_test.cc`. It uses a 22-byte footer with no
    schema and checks that both VerifyFooter and DecodeFooter return
    `EINVAL` with that message.
    
    How it was tested:
    - The new test passes with the fix and fails without it.
    - The full test suite passed: 431 tests, 16 tests skipped.
    - The clang-format check on the two changed files passed.
    
    Checklist:
    - [x] Tests added for the change
    - [ ] Lint (pre-commit hooks) passed on all files. Not run: the hooks
    need network access to fetch their repositories, which the test
    environment does not have. The clang-format check above covers only the
    two changed files.
---
 src/nanoarrow/ipc/decoder.c       |  4 ++++
 src/nanoarrow/ipc/decoder_test.cc | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/src/nanoarrow/ipc/decoder.c b/src/nanoarrow/ipc/decoder.c
index fa2fbe86..63006862 100644
--- a/src/nanoarrow/ipc/decoder.c
+++ b/src/nanoarrow/ipc/decoder.c
@@ -1977,6 +1977,10 @@ ArrowErrorCode ArrowIpcDecoderDecodeFooter(struct 
ArrowIpcDecoder* decoder,
   const uint8_t* footer_data =
       data.data.as_uint8 + data.size_bytes - footer_and_size_and_magic_size;
   ns(Footer_table_t) footer = ns(Footer_as_root(footer_data));
+  if (ns(Footer_schema(footer)) == NULL) {
+    ArrowErrorSet(error, "Footer has no schema");
+    return EINVAL;
+  }
 
   NANOARROW_RETURN_NOT_OK(
       ArrowIpcDecoderDecodeSchemaHeader(decoder, ns(Footer_schema(footer)), 
error));
diff --git a/src/nanoarrow/ipc/decoder_test.cc 
b/src/nanoarrow/ipc/decoder_test.cc
index 7293b121..3c18746c 100644
--- a/src/nanoarrow/ipc/decoder_test.cc
+++ b/src/nanoarrow/ipc/decoder_test.cc
@@ -1395,6 +1395,28 @@ TEST(NanoarrowIpcTest, NanoarrowIpcFooterSizeOverflow) {
   EXPECT_EQ(ArrowIpcDecoderDecodeFooter(decoder.get(), data, &error), ESPIPE);
 }
 
+TEST(NanoarrowIpcTest, NanoarrowIpcFooterMissingSchema) {
+  struct ArrowError error;
+
+  nanoarrow::ipc::UniqueDecoder decoder;
+  ArrowIpcDecoderInit(decoder.get());
+
+  // A Footer flatbuffer with an empty table (no schema, no blocks), followed 
by
+  // the footer size (12) and the magic bytes
+  alignas(8) const uint8_t footer_bytes[] = {
+      8, 0, 0, 0, 4, 0, 4, 0, 4, 0, 0, 0, 12, 0, 0, 0, 'A', 'R', 'R', 'O', 
'W', '1'};
+  struct ArrowBufferView data = {{footer_bytes}, sizeof(footer_bytes)};
+
+  EXPECT_EQ(ArrowIpcDecoderVerifyFooter(decoder.get(), data, &error), EINVAL);
+  EXPECT_STREQ(error.message, "Footer has no schema");
+
+  EXPECT_EQ(ArrowIpcDecoderPeekFooter(decoder.get(), data, &error), 
NANOARROW_OK)
+      << error.message;
+  error.message[0] = '\0';
+  EXPECT_EQ(ArrowIpcDecoderDecodeFooter(decoder.get(), data, &error), EINVAL);
+  EXPECT_STREQ(error.message, "Footer has no schema");
+}
+
 #if defined(NANOARROW_BUILD_TESTS_WITH_ARROW)
 class ArrowTypeParameterizedTestFixture
     : public ::testing::TestWithParam<std::shared_ptr<arrow::DataType>> {

Reply via email to