-
Notifications
You must be signed in to change notification settings - Fork 20
5.4.26 #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
5.4.26 #113
Changes from all commits
c7a9c24
d6cbf0a
2d11156
5f33116
ffdad17
bc8fb8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
| /* | ||
| * inc/purl_scan.h | ||
| * | ||
| * SCANOSS Inventory Scanner | ||
| * | ||
| * Copyright (C) 2018-2024 SCANOSS.COM | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 2 of the License, or | ||
| * (at your option) any later version. | ||
|
|
||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
|
|
||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #ifndef __PURL_SCAN_H | ||
| #define __PURL_SCAN_H | ||
|
|
||
| /** | ||
| * @brief Resolve the purls and url hashes related to a file MD5. | ||
| * | ||
| * Looks up the given file MD5 in the KB (url and file tables) and prints, in | ||
| * JSON, the unique purls associated with that file along with every url hash | ||
| * (url_id) where the file was seen and the best (lowest) KB rank found for | ||
| * each purl. | ||
| * | ||
| * @param file_md5_hex file MD5 in hex (32 chars) | ||
| * @return EXIT_SUCCESS on success, EXIT_FAILURE on invalid input | ||
| */ | ||
| int purl_scan(char *file_md5_hex); | ||
|
|
||
| /** | ||
| * @brief Report the details of one or more components identified by url hash. | ||
| * | ||
| * Accepts a single url_hash (url_id) or a comma-separated list. Each hash is | ||
| * looked up in the KB and its component details are rendered in JSON, reusing | ||
| * the same rendering used in regular scan reports. Output is always an array | ||
| * under the "results" key, one entry per valid hash: | ||
| * {"results": [{"url_hash": "...", "component": {...}}, ...]}. | ||
| * Invalid hashes are skipped with a stderr warning. | ||
| * | ||
| * @param url_hash_list comma-separated url hashes in hex (32 chars each) | ||
| * @return EXIT_SUCCESS if at least one valid hash was processed, | ||
| * EXIT_FAILURE if input is null/empty or no hash was valid | ||
| */ | ||
| int component_scan(char *url_hash_list); | ||
|
|
||
| /** | ||
| * @brief Run a snippet-only scan whose WFP input comes from stdin. | ||
| * | ||
| * Reads a WFP block (same format used by `-w` scans) from stdin, runs the | ||
| * snippet selection pipeline (no full-file lookup, no component resolution) | ||
| * and prints a JSON report listing the file_md5 candidates grouped by snippet | ||
| * region, together with their input/oss line ranges. Candidate cohort size is | ||
| * controlled by the tolerance set via -T (match_list_tolerance_set). | ||
| * | ||
| * @return EXIT_SUCCESS on success, EXIT_FAILURE on invalid/empty input | ||
| */ | ||
| int snippet_scan_stdin(void); | ||
|
|
||
| /** | ||
| * @brief Run a snippet-only scan whose WFP input is passed as a string. | ||
| * | ||
| * Same behavior as snippet_scan_stdin() but reads the WFP block from the | ||
| * provided in-memory buffer. Used by `-S "<wfp>"` so callers (e.g. FlexAPI) | ||
| * can pass the WFP directly as an argv value instead of piping it via stdin. | ||
| * | ||
| * @param wfp NUL-terminated buffer holding the WFP block | ||
| * @return EXIT_SUCCESS on success, EXIT_FAILURE on invalid/empty input | ||
| */ | ||
| int snippet_scan_string(const char *wfp); | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |
| #include "decrypt.h" | ||
| #include <ldb.h> | ||
| #include "debug.h" | ||
| #include "limits.h" | ||
| #include <unistd.h> | ||
|
|
||
| /** | ||
|
|
@@ -100,6 +101,16 @@ void mz_get_key(struct ldb_table kb, char *key) | |
| /* Decompress */ | ||
| MZ_DEFLATE(&job); | ||
|
|
||
| /* Reject files whose content exceeds the configured maximum size */ | ||
| if (job.data_ln > max_file_content_size) | ||
| { | ||
| fprintf(stderr, "File content size (%.2f MB) exceeds the maximum allowed (%lu MB). Use --max-file-content-size to change the limit.\n", (double) job.data_ln / (1024 * 1024), (unsigned long) (max_file_content_size / (1024 * 1024))); | ||
| free(job.data); | ||
| free(job.key); | ||
| free(job.mz); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
|
|
||
|
Comment on lines
+104
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Limit check looks correct; note The decompressed-size guard and cleanup ordering are correct. Be aware the effective behavior depends on input validation for 🤖 Prompt for AI Agents |
||
| job.data[job.data_ln] = 0; | ||
| printf("%s", job.data); | ||
| return; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Validate
--max-file-content-sizeinput.strtoullreturns0for non-numeric input, and an explicit0is accepted as-is. Either case setsmax_file_content_size = 0, which makesmz_get_key()(src/mz.c Line 105) reject every file with the "exceeds the maximum allowed" error. Consider rejecting0/unparseable values, or treating0as "unlimited".🛡️ Suggested guard
📝 Committable suggestion
🤖 Prompt for AI Agents