Copilot commented on code in PR #13738: URL: https://github.com/apache/trafficserver/pull/13738#discussion_r4122658513
########## tests/fuzzing/fuzz_chunked.cc: ########## @@ -0,0 +1,97 @@ +/** @file + + fuzzing proxy/http/ChunkedHandler + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + See the NOTICE file distributed with this work for additional information regarding copyright + ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software distributed under the License + is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the License for the specific language governing permissions and limitations under + the License. +*/ + +#include "proxy/http/HttpTunnel.h" +#include "proxy/hdrs/HTTP.h" + +#include "iocore/eventsystem/IOBuffer.h" +#include "records/RecordsConfig.h" +#include "tscore/Layout.h" + +#include <algorithm> +#include <cstddef> +#include <cstdint> + +#define kMinInputLength 2 +#define kMaxInputLength (64 * 1024) +#define TEST_THREADS 1 + +extern int cmd_disable_pfreelist; + +namespace +{ +bool +DoInitialization() +{ + Layout::create(); + RecProcessInit(); + LibRecordsConfigInit(); + + ink_event_system_init(EVENT_SYSTEM_MODULE_PUBLIC_VERSION); + eventProcessor.start(TEST_THREADS); + static EThread *main_thread = new EThread; + main_thread->set_specific(); + http_init(); + + return true; +} + +void +fuzz_chunked_content(const uint8_t *data, size_t size, size_t fragment_size, bool strict) +{ + MIOBuffer *buffer = new_MIOBuffer(BUFFER_SIZE_INDEX_4K); + IOBufferReader *reader = buffer->alloc_reader(); + + ChunkedHandler handler; + handler.init_by_action(reader, ChunkedHandler::Action::DECHUNK, false, strict); + handler.dechunked_reader = handler.dechunked_buffer->alloc_reader(); + handler.state = ChunkedHandler::ChunkedState::READ_SIZE; + + for (size_t offset = 0; offset < size;) { + size_t length = std::min(fragment_size, size - offset); + buffer->write(data + offset, length); + offset += length; + + if (handler.process_chunked_content().second) { + break; + } + } + + handler.clear(); + free_MIOBuffer(buffer); +} +} // namespace + +extern "C" int +LLVMFuzzerTestOneInput(const uint8_t *input_data, size_t size_data) +{ + if (size_data < kMinInputLength || size_data > kMaxInputLength) { + return 0; + } + + cmd_disable_pfreelist = true; + [[maybe_unused]] static bool initialized = DoInitialization(); + + size_t fragment_size = static_cast<size_t>(1) << (input_data[0] & 7); + fuzz_chunked_content(input_data + 1, size_data - 1, fragment_size, true); Review Comment: Every added seed is LF-delimited, so this strict invocation rejects each one at the first size-line terminator and never seeds strict parsing of chunk bodies, extensions, or trailers. Keep the intentionally ambiguous LF case, but provide CRLF-delimited normal seeds for the multiple-chunk and extension/trailer paths. ########## tests/fuzzing/corpus/chunked/extensions-and-trailers: ########## @@ -0,0 +1,6 @@ +3a;name=value;quoted="a\\\"b" Review Comment: The harness consumes the first byte as the fragmentation selector, so this seed is actually parsed as an `a` (10-byte) chunk, while the following body contains 58 bytes. The leftover digits are then interpreted as another chunk-size line, and the advertised zero chunk and trailers are never reached. Keep the selector `3`, but add the intended `3a` size after it. -- 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]
