Alchuang22-dev opened a new issue, #1106:
URL: https://github.com/apache/tsfile/issues/1106

   ### Language
   
   C++
   
   ### Description
   
   The bug is reported by codex with human review*
   
   SPRINTZ can silently return incorrect FLOAT and DOUBLE values when a packed 
block contains a transition from negative to positive values.
   
   Encoding and decoding both return success, but the decoded values differ 
from the input. This is reproducible directly through the SDK codecs, without 
involving TsFile I/O or the CLI.
   
   
   
   ### Reproduction steps
   
   Run the following code using the default FIRE predictor:
   
   ```cpp
   #include <iostream>
   
   #include "encoding/float_sprintz_decoder.h"
   #include "encoding/float_sprintz_encoder.h"
   #include "reader/tsfile_reader.h"
   
   int main() {
       storage::libtsfile_init();
       const float values[] = {
           -4.5f, -3.5f, -2.5f, -1.5f, 0.5f,
           1.5f, 2.5f, 3.5f, 4.5f
       };
   
       storage::FloatSprintzEncoder encoder;
       common::ByteStream stream(128, common::MOD_ENCODER_OBJ);
       for (float value : values) {
           encoder.encode(value, stream);
       }
       encoder.flush(stream);
   
       storage::FloatSprintzDecoder decoder;
       for (float expected : values) {
           float actual = 0;
           int rc = decoder.read_float(actual, stream);
           std::cout << "expected=" << expected << " actual=" << actual
                     << " rc=" << rc << '\n';
       }
   }
   ```
   
   The same sequence also reproduces the problem with `DoubleSprintzEncoder` 
and `DoubleSprintzDecoder`.
   
   ```text
   Expected: -4.5, -3.5, -2.5, -1.5,  0.5,  1.5,  2.5,  3.5,  4.5
   Actual:   -4.5, -3.5, -2.5, -1.5, -0.5, -1.5, -2.5, -3.5, -4.5
   ```
   
   ### Version
   
   C++ `2.5.1.dev`, local CMake Debug build on macOS arm64 with Apple Clang.
   
   ### Additional context
   
   - The residual mapping uses signed arithmetic: `raw_pred <= 0 ? -2 * 
raw_pred : 2 * raw_pred - 1`. UBSan reports signed overflow for both FLOAT and 
DOUBLE in this reproduction.
   - The decoder interprets mapped residuals using signed arithmetic as well. 
Once the mapped value occupies the highest bit, the inverse mapping does not 
recover the original residual.
   - Existing FLOAT/DOUBLE extreme-value tests contain only seven values. They 
exercise the Gorilla tail fallback rather than the SPRINTZ packed-block path, 
which requires one base value plus eight residuals.
   - Existing longer increasing-value tests use positive values and do not 
cover this transition.
   
   A fix should cover both encoding and decoding, add mixed-sign packed-block 
regression tests for FLOAT and DOUBLE, and verify compatibility with the Java 
implementation. Java behavior has not yet been verified.


-- 
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]

Reply via email to