Fix(license): IP list truncated at 4KB causing permanent data loss

This commit is contained in:
yuanyuanxiang
2026-05-25 21:04:36 +02:00
parent d6fb612475
commit 620aaf6827
2 changed files with 41 additions and 37 deletions

View File

@@ -11,6 +11,7 @@
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string>
#include <map>
@@ -36,24 +37,20 @@ public:
if (!filePath || !filePath[0])
return false;
FILE* f = nullptr;
#ifdef _MSC_VER
if (fopen_s(&f, filePath, "r") != 0 || !f)
std::ifstream f(filePath);
if (!f.is_open())
return false;
#else
f = fopen(filePath, "r");
if (!f)
return false;
#endif
// 不再使用固定行缓冲:超过 4KB 的行(如团购授权数百个 IP 的列表)会被
// fgets 拆成多段,第二段不带 '=' 会被 ParseLine 丢弃 → 显示截断。
// std::getline 按行读 std::string无长度上限。
std::string currentSection;
char line[4096];
while (fgets(line, sizeof(line), f)) {
ParseLine(line, currentSection);
std::string line;
while (std::getline(f, line)) {
if (!line.empty()) {
ParseLine(&line[0], currentSection);
}
}
fclose(f);
return true;
}
@@ -76,13 +73,11 @@ public:
while (lineEnd < end && *lineEnd != '\n' && *lineEnd != '\r')
lineEnd++;
// 复制行内容
// 不再限制行长度(原 4096 上限会悄无声息地丢弃长行)
size_t lineLen = lineEnd - p;
if (lineLen > 0 && lineLen < 4096) {
char line[4096];
memcpy(line, p, lineLen);
line[lineLen] = '\0';
ParseLine(line, currentSection);
if (lineLen > 0) {
std::string line(p, lineLen);
ParseLine(&line[0], currentSection);
}
// 跳过换行符
@@ -100,24 +95,17 @@ public:
if (!filePath || !filePath[0])
return false;
FILE* f = nullptr;
#ifdef _MSC_VER
if (fopen_s(&f, filePath, "r") != 0 || !f)
std::ifstream f(filePath);
if (!f.is_open())
return false;
#else
f = fopen(filePath, "r");
if (!f)
return false;
#endif
std::string currentSection;
char line[4096];
while (fgets(line, sizeof(line), f)) {
ParseLine(line, currentSection);
std::string line;
while (std::getline(f, line)) {
if (!line.empty()) {
ParseLine(&line[0], currentSection);
}
}
fclose(f);
return true;
}