You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++][Parquet] DeltaBitPackDecoder expects all miniblock bitwidths to be present for the last block #14923
Describe the bug, including details regarding any error messages, version, and platform.
This is a follow-up to this discussion.
Arrow's reader is not compliant with the spec, and requires all miniblock bitwidth values of the last block even if not necessary. This forces arrow writer to write all miniblock bitwidths to be able to roundtrip which is not a big issue. However it does mean Arrow reader would not be able to read bitpacked buffer written by another parquet writer that does not write all miniblock bitwidths.
Sorry this took a while, here's a test with examples generated with this->Execute(65, 1);:
Hi rok, can you provide the environment you're using and the error messages? Since that I cannot reproduce the fatal on my environment (ARROW_SIMD_LEVEL=NEON in aarch64) @rok
Hey @mapleFU. I'm on Ryzen 7 Linux desko 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux.
If you just apply the change below and run arrow test suite you should hit the same issue.
diff --git a/cpp/src/parquet/encoding.cc b/cpp/src/parquet/encoding.cc
index 720b6fcb1..aef079da3 100644
--- a/cpp/src/parquet/encoding.cc+++ b/cpp/src/parquet/encoding.cc@@ -2248,9 +2248,6 @@ void DeltaBitPackEncoder<DType>::FlushBlock() {
// needed to store the values, the bytes storing the bit widths of the unneeded
// miniblocks are still present, their value should be zero, but readers must accept
// arbitrary values as well.
- for (uint32_t i = num_miniblocks; i < mini_blocks_per_block_; i++) {- bit_width_data[i] = 0;- }
DCHECK_EQ(values_current_block_, 0);
@rok I reproduce this problem on my pc by applying the change below:
- for (uint32_t i = num_miniblocks; i < mini_blocks_per_block_; i++) {- bit_width_data[i] = 0;- }+ // for (uint32_t i = num_miniblocks; i < mini_blocks_per_block_; i++) {+ // bit_width_data[i] = 0;+ // }
But I think the code just break our standard, by unuse bit_width_data[i] = 0;, we will leak some mini-blocks, the real code would be:
for (uint32_t i = num_miniblocks; i < mini_blocks_per_block_; i++) {
bit_width_data[i] = 1/* or other random bit width for miniblock */;
for (uint32_t j = 0; j < values_per_mini_block_; j++) {
bit_writer_.PutValue(0, bit_width_data[i]);
}
}
And previous case would lead to:
write less bits than expected for the last block
Last block bit_width_data random caused by uninitialized memory
So I think here is no bug. If I'm wrong, please correct me @rok
If, in the last block, less than miniblocks are needed to store the values, the bytes storing the bit widths of the unneeded miniblocks are still present, their value should be zero, but readers must accept arbitrary values as well.
I'm not sure how other encoder authors would interpret this, but I expected that uninitialized bit_width_data[i] would produce a random int that wouldn't cause problems roundtripping. My interpretation is probably wrong. Maybe we should propose to make the spec clearer or stricter?
So, once it reaches the last block, it will just read the last mini-block with data, the remaining buffer will not be read or checked.
@mapleFU I am worried about this part of the spec:
I'm not sure how other encoder authors would interpret this, but I expected that uninitialized bit_width_data[i] would produce a random int that wouldn't cause problems roundtripping. My interpretation is probably wrong. Maybe we should propose to make the spec clearer or stricter?
Hi, I think the arbitrary value means the bit_width could be 1, 2... But once the bit width is not zero, the miniblock should have corresbond bits.
And I met the exceptions because:
The bit_width is greater than 32
I didn't meet the case that it reaches EOF, because the implemention already handle this cases.
If, in the last block, less than miniblocks are needed to store the values, the bytes storing the bit widths of the unneeded miniblocks are still present, their value should be zero, but readers must accept arbitrary values as well. There are no additional padding bytes for the miniblock bodies though, as if their bit widths were 0 (regardless of the actual byte values). The reader knows when to stop reading by keeping track of the number of values read.
privatevoidloadNewBlockToBuffer() throwsIOException {
try {
minDeltaInCurrentBlock = BytesUtils.readZigZagVarLong(in);
} catch (IOExceptione) {
thrownewParquetDecodingException("can not read min delta in current block", e);
}
readBitWidthsForMiniBlocks();
// mini block is atomic for reading, we read a mini block when there are more values leftinti;
for (i = 0; i < config.miniBlockNumInABlock && valuesBuffered < totalValueCount; i++) {
BytePackerForLongpacker = Packer.LITTLE_ENDIAN.newBytePackerForLong(bitWidths[i]);
unpackMiniBlock(packer);
}
//calculate values from deltas unpacked for current blockintvalueUnpacked=i*config.miniBlockSizeInValues;
for (intj = valuesBuffered-valueUnpacked; j < valuesBuffered; j++) {
intindex = j;
valuesBuffer[index] += minDeltaInCurrentBlock + valuesBuffer[index - 1];
}
}
privatevoidreadBitWidthsForMiniBlocks() {
for (inti = 0; i < config.miniBlockNumInABlock; i++) {
try {
bitWidths[i] = BytesUtils.readIntLittleEndianOnOneByte(in);
} catch (IOExceptione) {
thrownewParquetDecodingException("Can not decode bitwidth in block header", e);
}
}
}
privateint[] bitWidths;
when readBitWidthsForMiniBlocks, it will not check it's size
Only when valuesBuffered < totalValueCount, it will use bitWidths and unpack mini block
I think your fixing is much better, let's make it into our codebase :)
Activity
pitrou commentedon Dec 13, 2022
cc @shanhuuang
rok commentedon Dec 13, 2022
The decoder in question is here.
pitrou commentedon Dec 13, 2022
@rok Is it possible for you to generate a small data page that would exhibit the issue?
rok commentedon Dec 13, 2022
@pitrou sure. By that you mean a single parquet file?
pitrou commentedon Dec 13, 2022
That would work, but it can also be a small piece of data suitable for
Decoder::SetData(...)rok commentedon Dec 20, 2022
Sorry this took a while, here's a test with examples generated with
this->Execute(65, 1);:mapleFU commentedon Dec 23, 2022
Hi rok, can you provide the environment you're using and the error messages? Since that I cannot reproduce the fatal on my environment (
ARROW_SIMD_LEVEL=NEONin aarch64) @rokrok commentedon Dec 23, 2022
Hey @mapleFU. I'm on Ryzen 7
Linux desko 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux.If you just apply the change below and run arrow test suite you should hit the same issue.
mapleFU commentedon Dec 28, 2022
Cannot reproduce this problem on my macos, guess maybe the problem comes from SIMD unpack or other. I will keep the diff and try it on my pc tonight.
mapleFU commentedon Dec 28, 2022
@rok I reproduce this problem on my pc by applying the change below:
But I think the code just break our standard, by unuse
bit_width_data[i] = 0;, we will leak some mini-blocks, the real code would be:And previous case would lead to:
bit_width_datarandom caused by uninitialized memorySo I think here is no bug. If I'm wrong, please correct me @rok
mapleFU commentedon Dec 28, 2022
And after gothrough the code in
DeltaBitPackDecoder, I found it a bit hacking for border handling. Get internal will have:So, once it reaches the last block, it will just read the last mini-block with data, the remaining buffer will not be read or checked.
rok commentedon Dec 28, 2022
@mapleFU I am worried about this part of the spec:
I'm not sure how other encoder authors would interpret this, but I expected that uninitialized
bit_width_data[i]would produce a randomintthat wouldn't cause problems roundtripping. My interpretation is probably wrong. Maybe we should propose to make the spec clearer or stricter?That sounds like a good idea!
mapleFU commentedon Dec 29, 2022
Hi, I think
the arbitrary valuemeans the bit_width could be 1, 2... But once the bit width is not zero, the miniblock should have corresbond bits.And I met the exceptions because:
bit_widthis greater than 32I didn't meet the case that it reaches EOF, because the implemention already handle this cases.
@rok
pitrou commentedon Jan 3, 2023
@mapleFU Please read the spec again:
mapleFU commentedon Jan 3, 2023
Damn...It's really trickey, maybe I can see how parquet-mr implements it.
Seems that DELTA_BINARY_PACK is really a bug and ub creator
pitrou commentedon Jan 3, 2023
It should actually be quite simple:
mapleFU commentedon Jan 3, 2023
The code looks simple and great. parquet-mr will not check the bit-length. It's really trickey :(
pitrou commentedon Jan 3, 2023
What do you mean?
mapleFU commentedon Jan 3, 2023
The code is like:
readBitWidthsForMiniBlocks, it will not check it's sizevaluesBuffered < totalValueCount, it will usebitWidthsand unpack mini blockI think your fixing is much better, let's make it into our codebase :)
raulcd commentedon Jan 11, 2023
I am going to remove the milestone in preparation for the release, please if this is a blocker add the label
Priority: BlockerGH-14923: [C++][Parquet] Fix DELTA_BINARY_PACKED problem on reading t…