Skip to content

Commit b114241

Browse files
authored
Fix JSON reader panic for non-nullable zero-size FixedSizeList (#9810)
# Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. --> - Closes #9780. # Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> # What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Use `FixedSizeListArray::try_new_with_length` to avoid panic when decoding degenerate non-nullable `FixedSizeList` # Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Yes # Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please call them out. --> Bug fixed
1 parent ba7dada commit b114241

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

arrow-json/src/reader/list_array.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,13 @@ impl ArrayDecoder for FixedSizeListArrayDecoder {
209209
let values = self.decoder.decode(tape, &child_pos)?;
210210
let nulls = nulls.as_mut().and_then(|x| x.finish());
211211

212-
let array = FixedSizeListArray::try_new(self.field.clone(), self.size, values, nulls)?;
212+
let array = FixedSizeListArray::try_new_with_length(
213+
self.field.clone(),
214+
self.size,
215+
values,
216+
nulls,
217+
pos.len(),
218+
)?;
213219
Ok(Arc::new(array))
214220
}
215221
}

arrow-json/src/reader/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,6 +2369,32 @@ mod tests {
23692369
assert!(values.is_null(5));
23702370
}
23712371

2372+
#[test]
2373+
fn test_fixed_size_list_zero_size_non_nullable() {
2374+
let buf = r#"
2375+
{"a": []}
2376+
{"a": []}
2377+
{"a": []}
2378+
"#;
2379+
2380+
let field = Field::new_list_field(DataType::Int32, true);
2381+
let schema = Arc::new(Schema::new(vec![Field::new(
2382+
"a",
2383+
DataType::FixedSizeList(Arc::new(field), 0),
2384+
false,
2385+
)]));
2386+
2387+
let batches = do_read(buf, 1024, false, false, schema);
2388+
assert_eq!(batches.len(), 1);
2389+
2390+
let col = batches[0].column(0).as_fixed_size_list();
2391+
assert_eq!(col.len(), 3);
2392+
assert_eq!(col.value_length(), 0);
2393+
2394+
let values = col.values().as_primitive::<Int32Type>();
2395+
assert!(values.values().is_empty());
2396+
}
2397+
23722398
#[test]
23732399
fn test_fixed_size_list_wrong_size() {
23742400
let buf = r#"{"a": [1, 2, 3]}"#;

0 commit comments

Comments
 (0)