Skip to content

Infinite loop in ASCII decoder when encountering invalid bytes with replacement_handler #50

@captainurist

Description

@captainurist

When decoding ASCII data containing invalid bytes (>= 0x80) using replacement_handler, the transcoding loop enters an infinite loop because the input iterator is not advanced before calling the error handler.

Repro:

#include <string>
#include <span>
#include <iostream>
#include <ztd/text.hpp>

int main() {
    // Invalid ASCII byte (0x80 is >= 0x80, not valid ASCII)
    std::string input = "\x80";
    std::span<const char> input_span(input.data(), input.size());

    // This will hang forever
    auto result = ztd::text::transcode(input_span, ztd::text::ascii, ztd::text::compat_utf8,
                                       ztd::text::replacement_handler);

    std::cout << "Result: " << result << std::endl;
    return 0;
}

My fix 5412d5e

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions