Copilot commented on code in PR #3853: URL: https://github.com/apache/avro/pull/3853#discussion_r3567637692
########## lang/c/tests/test_avro_4284.c: ########## @@ -0,0 +1,143 @@ +/* + * 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 + * + * https://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. + */ + +/* + * AVRO-4284: a data-file block is decompressed according to the file's codec. + * A block with a very high compression ratio (or a malformed block) can expand + * to far more memory than its compressed size. Decompression must reject a + * block whose decompressed size would exceed the configured maximum, which + * these tests set to a small value via AVRO_MAX_DECOMPRESS_LENGTH. + */ + +#include <avro.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "codec.h" + +/* Size of the highly compressible payload used to build an over-large block. */ +#define PAYLOAD_SIZE (4 * 1024 * 1024) /* 4 MiB of zeros */ +/* Decompression limit for the test, smaller than the payload. */ +#define TEST_LIMIT "1048576" /* 1 MiB */ + +/* + * Compress `payload` with the named codec and attempt to decompress it with a + * decompression limit smaller than the payload. Returns 0 if the codec is not + * available (test skipped for that codec), 1 on test failure, 2 on success. + */ +static int +check_codec_rejects_oversized(const char *name, const char *payload, int64_t payload_len) +{ + struct avro_codec_t_ codec; + memset(&codec, 0, sizeof(codec)); + + if (avro_codec(&codec, name) != 0) { + fprintf(stderr, " codec %s not available, skipping\n", name); + return 0; + } Review Comment: The test treats any avro_codec() failure as "codec not available" and skips, which can hide real regressions (e.g., codec compiled in but initialization fails due to an unexpected error). Only skip when the failure is specifically "Unknown codec ..."; otherwise fail the test with the reported error. -- 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]
