由于NUL字符[closed],csv文件未被解析

pxy2qtax  于 7个月前  发布在  其他
关注(0)|答案(1)|浏览(66)

**已关闭。**此问题需要debugging details。目前不接受答案。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
22天前关闭
Improve this question
我写了一个CSV文件的解析器。我使用Java的SuperCSV库。
一开始一切正常,但现在我面临一个问题。我开始收到奇怪的CSV文件。我总是用Notepad++打开它们。此时文件看起来很正常,右下角的编码是标准的UTF-8,这是确定的:
x1c 0d1x的数据
同时,文本中还有奇怪的NUL字符(带一个字母“L”):



由于它们,文件不会被解析。我开始调试代码,这是我发现的:首先有一个文件头,其中有列的名称。然后有2行没有这个NULL字符。这两行是正常解析的:



但是第三行第一次包含NUL字符,从那一刻起,所有的东西都被错误地解析了。库停止识别行尾(\n字符)和NULL字符(符号|),并试图将几行解析为一行:

// I use this preference:
private static final CsvPreference CSV_PREFERENCE = new CsvPreference.Builder('\u0000', '|', "\n").build();

字符串

我们得到相应的错误:

2023-10-22T13:18:27,208: ERROR [executor-4] service.ParseServiceImpl - The number of columns to be processed (33) must match the number of CellProcessors (13): check that the number of CellProcessors you have defined matches the expected number of columns being read/written
org.supercsv.exception.SuperCsvException: The number of columns to be processed (33) must match the number of CellProcessors (13): check that the number of CellProcessors you have defined matches the expected number of columns being read/written
    at org.supercsv.util.Util.executeCellProcessors(Util.java:78) ~[super-csv-2.1.0.jar:?]
    at org.supercsv.io.AbstractCsvReader.executeProcessors(AbstractCsvReader.java:203) ~[super-csv-2.1.0.jar:?]
    at org.supercsv.io.CsvBeanReader.read(CsvBeanReader.java:206) ~[super-csv-2.1.0.jar:?]


请告诉我,这个奇怪的NULL符号是什么?为什么会出现?因为这个,解析停止工作。

jei2mxaa

jei2mxaa1#

根据经验,您应该始终对输入文件进行清理。删除任何您不需要的特殊字符,或可能用作攻击向量以危及安全性的特殊字符,或您知道您无法处理或在上下文中无效的特殊字符。
读取此CSV文件时,请选择您准备好支持的一系列asktop/UTF-8字符,然后从文件中删除其他所有内容。您需要不信任创建此CSV文件的人。
如果你拥有CSV源系统,可能只需要看看它是如何创建这个文件的,这可能会给你一个提示,为什么它要添加nul. NUL,实际上计算为零,不像null,它只是null。

相关问题