用短语模糊测试法,发现大模型生成代码时会推荐不存在的包。
HFuzzer: Testing Large Language Models for Package Hallucinations via Phrase-based Fuzzing
- 基于短语的模糊测试,生成多样且相关的编码任务
- 相比传统方法多发现2.6倍独特幻觉包,GPT-4o发现46个
- 适用于检测模型在编码与环境配置中的包幻觉问题
大型语言模型(LLMs)广泛用于代码生成,但在实际生产中因包幻觉存在严重安全风险,即模型推荐不存在的软件包。这些幻觉可能被攻击者利用,在软件供应链中注册恶意包。现有研究主要针对自然语言生成中的事实冲突幻觉,缺乏对包幻觉的系统性测试方法。为此,本文提出HFUZZER,一种基于短语的模糊测试框架,通过引导模型基于短语推断更广泛合理信息,生成多样化的编码任务。同时从包信息或编码任务中提取相关短语,确保任务与代码的相关性。在多个大模型上的评估显示,HFUZZER可触发所有测试模型的包幻觉。相比变异模糊测试,其识别出2.60倍更多唯一幻觉包,并生成更丰富任务。针对GPT-4o的测试发现46个独特幻觉包,进一步分析表明其不仅在代码生成中出现幻觉,还在环境配置阶段也存在该问题。
原文摘要 · Abstract (English)
Large Language Models (LLMs) are widely used for code generation, but they face critical security risks when applied to practical production due to package hallucinations, in which LLMs recommend non-existent packages. These hallucinations can be exploited in software supply chain attacks, where malicious attackers exploit them to register harmful packages. It is critical to test LLMs for package hallucinations to mitigate package hallucinations and defend against potential attacks. Although researchers have proposed testing frameworks for fact-conflicting hallucinations in natural language generation, there is a lack of research on package hallucinations. To fill this gap, we propose HFUZZER, a novel phrase-based fuzzing framework to test LLMs for package hallucinations. HFUZZER adopts fuzzing technology and guides the model to infer a wider range of reasonable information based on phrases, thereby generating enough and diverse coding tasks. Furthermore, HFUZZER extracts phrases from package information or coding tasks to ensure the relevance of phrases and code, thereby improving the relevance of generated tasks and code. We evaluate HFUZZER on multiple LLMs and find that it triggers package hallucinations across all selected models. Compared to the mutational fuzzing framework, HFUZZER identifies 2.60x more unique hallucinated packages and generates more diverse tasks. Additionally, when testing the model GPT-4o, HFUZZER finds 46 unique hallucinated packages. Further analysis reveals that for GPT-4o, LLMs exhibit package hallucinations not only during code generation but also when assisting with environment configuration.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。