shashank11yadav opened a new issue, #1022:
URL: https://github.com/apache/arrow-nanoarrow/issues/1022
### Describe the bug
`ArrowIpcDecoderDecodeFooter()` passes `Footer_schema(footer)` to the schema
decoders without checking it for NULL. For a well-formed footer flatbuffer that
has no `schema` field, the call aborts on flatcc's "null pointer table access"
assert (or dereferences NULL when built with `NDEBUG`) instead of returning an
error. `ArrowIpcDecoderVerifyFooter()` rejects the same input ("Footer has no
schema"), so only callers that decode without verifying first are affected.
### To reproduce
```c
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include "nanoarrow/nanoarrow.h"
#include "nanoarrow/nanoarrow_ipc.h"
int main(void) {
// Footer flatbuffer: root offset 8; vtable (size 4, table size 4); empty
table.
// No schema, no record batches. Then int32 footer size (12) and "ARROW1".
static const uint8_t buf[] = {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;
data.data.as_uint8 = buf;
data.size_bytes = sizeof(buf);
printf("EXPECTED: DecodeFooter returns an error code (EINVAL) for a footer
with no schema\n");
fflush(stdout);
fflush(stderr);
pid_t pid = fork();
if (pid < 0) return 2;
if (pid == 0) {
struct ArrowIpcDecoder decoder;
struct ArrowError error;
error.message[0] = '\0';
if (ArrowIpcDecoderInit(&decoder) != NANOARROW_OK) _exit(2);
if (ArrowIpcDecoderPeekFooter(&decoder, data, &error) != NANOARROW_OK)
_exit(2);
int rc = ArrowIpcDecoderDecodeFooter(&decoder, data, &error);
_exit(rc == NANOARROW_OK ? 3 : 0);
}
int status = 0;
if (waitpid(pid, &status, 0) < 0) return 2;
if (WIFSIGNALED(status)) {
printf("ACTUAL: DecodeFooter crashed (signal %d)\n", WTERMSIG(status));
return 1;
}
int code = WEXITSTATUS(status);
if (code == 3) {
printf("ACTUAL: DecodeFooter returned NANOARROW_OK\n");
return 1;
}
printf("ACTUAL: DecodeFooter returned an error code (child exit %d)\n",
code);
return 0;
}
```
Output on `main` (1292ac0):
```
EXPECTED: DecodeFooter returns an error code (EINVAL) for a footer with no
schema
ACTUAL: DecodeFooter crashed (signal 6)
```
The crash is flatcc's assert in `flatcc_generated.h`
(`org_apache_arrow_flatbuf_Schema_endianness: Assertion 't__tmp != 0 && "null
pointer table access"' failed`), printed to stderr just before the ACTUAL line.
The 0.9.0 tag gives the same output.
### Expected behavior
`nanoarrow_ipc.h` says `ArrowIpcDecoderDecodeFooter()` "Returns EINVAL if
the content of the footer cannot be decoded". The header-side twin already does
this: #960 added a NULL message-header check to
`ArrowIpcDecoderDecodeHeader()`, which has the same "In almost all cases this
should be preceded by" a verify call wording.
### Versions
- nanoarrow 0.9.0 and `main` @ 1292ac0 (both affected)
- gcc 15.2.0, Linux aarch64; CMake Debug build with `-DNANOARROW_IPC=ON`;
repro built with `-std=c11 -g -fsanitize=address,undefined`
### Additional context
Root cause: `src/nanoarrow/ipc/decoder.c:1982-1985`, `Footer_schema(footer)`
goes straight into `ArrowIpcDecoderDecodeSchemaHeader` /
`ArrowIpcDecoderDecodeSchemaImpl`. A NULL check after `Footer_as_root` that
sets "Footer has no schema" and returns EINVAL (the same message
`ArrowIpcDecoderVerifyFooter()` uses) would fix it. The API is marked as public
only for integration testing.
I have a fix with a regression test ready and will open a pull request for
it right after filing this issue; it will link back here.
--
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]