[ 
https://issues.apache.org/jira/browse/IGNITE-25150?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Dmitrii Zabotlin updated IGNITE-25150:
--------------------------------------
    Description: 
{{bytes_view}} class implemented as a subclass of the 
{{{}basic_string_view{}}}, which implies that there is termination element as 
in the string (0-byte), it is used inside the {{char_traits::length}} static 
function. This {{length}} function used in some {{find}} methods of the 
{{{}basic_string_view{}}}.

{{length}} function by the 
[definition|https://timsong-cpp.github.io/cppwp/n4659/char.traits.require] 
counts the length of the sequence up to the zero-element({{{}CharT(){}}}), 
which makes no sense in case of the byte-buffer, we cannot use any value of the 
{{byte}} as a termination value.

Error could be easily reproduced with this test:
{code:c++}
TEST(example_suite, bytes_view) {
    const std::byte data[] = {
        std::byte(0x01), std::byte(0x02), std::byte(0x03), std::byte(0x04),
        std::byte(0x05), std::byte(0x06), std::byte(0x07), std::byte(0x08),
        std::byte(0x00), // <== Breaks search
        std::byte(0x09), std::byte(0x0A), std::byte(0x0B), std::byte(0x0C),
        std::byte(0x0D), std::byte(0x0E), std::byte(0x0F), std::byte(0x10),
    };

    ignite::bytes_view view(data);

    EXPECT_EQ(view.find(std::byte(0x01)), 0);
    EXPECT_EQ(view.find(std::byte(0x02)), 1);
    EXPECT_EQ(view.find(std::byte(0x03)), 2);
    EXPECT_EQ(view.find(std::byte(0x04)), 3);
    EXPECT_EQ(view.find(std::byte(0x05)), 4);
    EXPECT_EQ(view.find(std::byte(0x06)), 5);
    EXPECT_EQ(view.find(std::byte(0x07)), 6);
    EXPECT_EQ(view.find(std::byte(0x08)), 7);
    EXPECT_EQ(view.find(std::byte(0x09)), 9); // Find breaks on this line and 
below
    EXPECT_EQ(view.find(std::byte(0x0A)), 10);
    EXPECT_EQ(view.find(std::byte(0x0B)), 11);
    EXPECT_EQ(view.find(std::byte(0x0C)), 12);
    EXPECT_EQ(view.find(std::byte(0x0D)), 13);
    EXPECT_EQ(view.find(std::byte(0x0E)), 14);
    EXPECT_EQ(view.find(std::byte(0x0F)), 15);
    EXPECT_EQ(view.find(std::byte(0x10)), 16);
}
{code}
I'd suggest to reimplement {{bytes_view}} as close to {{span}} as it's possible 
or just use {{std::span}} if we allowed to require c++20 standard.

  was:
{{bytes_view}} class implemented as a subclass of the 
{{{}basic_string_view{}}}, which implies that there is termination element as 
in the string (0-byte), it is used inside the {{char_traits::length}} static 
function. This {{length}} function used in some {{find}} methods of the 
{{{}basic_string_view{}}}.

{{length}} function by the 
[definition|https://timsong-cpp.github.io/cppwp/n4659/char.traits.require] 
counts the length of the sequence up to the zero-element({{{}CharT(){}}}), 
which makes no sense in case of the byte-buffer, we cannot use any value of the 
{{byte}} as a termination value.

Error could be easily reproduced with this test:
{code:c++}
TEST(example_suite, bytes_view) {
    const std::byte data[] = {
        std::byte(0x01), std::byte(0x02), std::byte(0x03), std::byte(0x04),
        std::byte(0x05), std::byte(0x06), std::byte(0x07), std::byte(0x08),
        std::byte(0x00), // <== Breaks search
        std::byte(0x09), std::byte(0x0A), std::byte(0x0B), std::byte(0x0C),
        std::byte(0x0D), std::byte(0x0E), std::byte(0x0F), std::byte(0x10),
    };

    ignite::bytes_view view(data);

    EXPECT_EQ(view.find(std::byte(0x01)), 0);
    EXPECT_EQ(view.find(std::byte(0x02)), 1);
    EXPECT_EQ(view.find(std::byte(0x03)), 2);
    EXPECT_EQ(view.find(std::byte(0x04)), 3);
    EXPECT_EQ(view.find(std::byte(0x05)), 4);
    EXPECT_EQ(view.find(std::byte(0x06)), 5);
    EXPECT_EQ(view.find(std::byte(0x07)), 6);
    EXPECT_EQ(view.find(std::byte(0x08)), 7);
    EXPECT_EQ(view.find(std::byte(0x09)), 9); // Find breaks on this line and 
below
    EXPECT_EQ(view.find(std::byte(0x0A)), 10);
    EXPECT_EQ(view.find(std::byte(0x0B)), 11);
    EXPECT_EQ(view.find(std::byte(0x0C)), 12);
    EXPECT_EQ(view.find(std::byte(0x0D)), 13);
    EXPECT_EQ(view.find(std::byte(0x0E)), 14);
    EXPECT_EQ(view.find(std::byte(0x0F)), 15);
    EXPECT_EQ(view.find(std::byte(0x10)), 16);
}
{code}
I'd suggest to reimplement {{bytes_view}} as close to span as it's possible or 
just use {{std::span}} if we allowed to require c++20 standard.


> Find method of the bytes_view class may return incorrect results if there is 
> 0 byte inside the buffer 
> ------------------------------------------------------------------------------------------------------
>
>                 Key: IGNITE-25150
>                 URL: https://issues.apache.org/jira/browse/IGNITE-25150
>             Project: Ignite
>          Issue Type: Bug
>          Components: platforms
>            Reporter: Dmitrii Zabotlin
>            Assignee: Igor Sapego
>            Priority: Major
>              Labels: ignite-3
>
> {{bytes_view}} class implemented as a subclass of the 
> {{{}basic_string_view{}}}, which implies that there is termination element as 
> in the string (0-byte), it is used inside the {{char_traits::length}} static 
> function. This {{length}} function used in some {{find}} methods of the 
> {{{}basic_string_view{}}}.
> {{length}} function by the 
> [definition|https://timsong-cpp.github.io/cppwp/n4659/char.traits.require] 
> counts the length of the sequence up to the zero-element({{{}CharT(){}}}), 
> which makes no sense in case of the byte-buffer, we cannot use any value of 
> the {{byte}} as a termination value.
> Error could be easily reproduced with this test:
> {code:c++}
> TEST(example_suite, bytes_view) {
>     const std::byte data[] = {
>         std::byte(0x01), std::byte(0x02), std::byte(0x03), std::byte(0x04),
>         std::byte(0x05), std::byte(0x06), std::byte(0x07), std::byte(0x08),
>         std::byte(0x00), // <== Breaks search
>         std::byte(0x09), std::byte(0x0A), std::byte(0x0B), std::byte(0x0C),
>         std::byte(0x0D), std::byte(0x0E), std::byte(0x0F), std::byte(0x10),
>     };
>     ignite::bytes_view view(data);
>     EXPECT_EQ(view.find(std::byte(0x01)), 0);
>     EXPECT_EQ(view.find(std::byte(0x02)), 1);
>     EXPECT_EQ(view.find(std::byte(0x03)), 2);
>     EXPECT_EQ(view.find(std::byte(0x04)), 3);
>     EXPECT_EQ(view.find(std::byte(0x05)), 4);
>     EXPECT_EQ(view.find(std::byte(0x06)), 5);
>     EXPECT_EQ(view.find(std::byte(0x07)), 6);
>     EXPECT_EQ(view.find(std::byte(0x08)), 7);
>     EXPECT_EQ(view.find(std::byte(0x09)), 9); // Find breaks on this line and 
> below
>     EXPECT_EQ(view.find(std::byte(0x0A)), 10);
>     EXPECT_EQ(view.find(std::byte(0x0B)), 11);
>     EXPECT_EQ(view.find(std::byte(0x0C)), 12);
>     EXPECT_EQ(view.find(std::byte(0x0D)), 13);
>     EXPECT_EQ(view.find(std::byte(0x0E)), 14);
>     EXPECT_EQ(view.find(std::byte(0x0F)), 15);
>     EXPECT_EQ(view.find(std::byte(0x10)), 16);
> }
> {code}
> I'd suggest to reimplement {{bytes_view}} as close to {{span}} as it's 
> possible or just use {{std::span}} if we allowed to require c++20 standard.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to