fix: SAT 临时文件唯一化,修 DGJM.sat 读取越界

1. AcDbX3dSolid::CreateFromSat 的 temp\temp.sat 改为
   temp_<pid>_<原子序号>.sat,用完 DeleteFile。原来固定名且从不删除,
   两个 CAD 实例同时从 SAT 重建时会互相覆盖。

2. DGJM.sat 的读取统一改成「分配时补终止符 + 按实际读到的长度赋值」:
   new char[n] 之后直接赋给 CString 会把未初始化内存当字符串读到终止符,
   现在 new char[n+1] + memset,再用 CString(pszTxt, nRead) 明确长度。
   涉及 AcDbX3dSolid、AecDbEarthWormFitting、DGJMDlg、GJYXJMDlg、
   JMDBDlg、JMSJDlg 共 6 处。

DGJM.sat 本身仍是固定文件名,写读双方靠它隐式传递,本次不改名。
This commit is contained in:
company-desktop-computer committed 2026-10-21 23:39:47 +08:00
1 parent 54f24a93e4
commit e3fff2ad66
6 files changed
+49 -19

No files matched your search

@@ -129,11 +129,15 @@ bool FormatScriptFromSection(CString& sScr,STSection* pSection)
if (file.Open(sFullPath,CFile::modeRead)) if (file.Open(sFullPath,CFile::modeRead))
{ {
ULONGLONG dwFileLength = file.GetLength(); ULONGLONG dwFileLength = file.GetLength();
char* pszTxt = new char[dwFileLength]; int nLen = (int)dwFileLength;
file.Read(pszTxt,(UINT)dwFileLength); // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读
char* pszTxt = new char[nLen + 1];
::memset(pszTxt, 0, nLen + 1);
sRegionScrp = pszTxt; UINT nRead = file.Read(pszTxt, nLen);
sRegionScrp = CString(pszTxt, (int)nRead);
delete [] pszTxt; delete [] pszTxt;
file.Close(); file.Close();
@@ -2900,7 +2904,11 @@ bool AcDbX3dSolid::CreateFromSat(LPCTSTR pszSatFile,double dUnitScale)
//上一级目录 //上一级目录
int nPos = sFullPath.ReverseFind(_T('\\')); int nPos = sFullPath.ReverseFind(_T('\\'));
CString sPath = sFullPath.Mid(0,nPos + 1); CString sPath = sFullPath.Mid(0,nPos + 1);
sFullPath = sPath + _T("temp\\temp.sat");
// 每次用唯一文件名:多个 CAD 实例同时从 SAT 重建时不会互相覆盖
static LONG s_nSatSeq = 0;
sFullPath.Format(_T("%stemp\\temp_%lu_%ld.sat"),(LPCTSTR)sPath
,(unsigned long)::GetCurrentProcessId(),(long)::InterlockedIncrement(&s_nSatSeq));
CFile file; CFile file;
if (file.Open(sFullPath,CFile::modeCreate|CFile::modeWrite)) if (file.Open(sFullPath,CFile::modeCreate|CFile::modeWrite))
@@ -2912,6 +2920,8 @@ bool AcDbX3dSolid::CreateFromSat(LPCTSTR pszSatFile,double dUnitScale)
AcDbVoidPtrArray arPtr; AcDbVoidPtrArray arPtr;
AcDbBody::acisIn(sFullPath,arPtr); AcDbBody::acisIn(sFullPath,arPtr);
::DeleteFile(sFullPath);
//按照体积从大到小排序 //按照体积从大到小排序
Sort3dSolidByVol(arPtr); Sort3dSolidByVol(arPtr);
@@ -580,11 +580,15 @@ CString GetSectionScr(AcDbRegion* pReg)
if (file.Open(sFullPath,CFile::modeRead)) if (file.Open(sFullPath,CFile::modeRead))
{ {
ULONGLONG dwFileLength = file.GetLength(); ULONGLONG dwFileLength = file.GetLength();
char* pszTxt = new char[dwFileLength]; int nLen = (int)dwFileLength;
file.Read(pszTxt,(UINT)dwFileLength); // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读
char* pszTxt = new char[nLen + 1];
::memset(pszTxt, 0, nLen + 1);
sRegionScrp = pszTxt; UINT nRead = file.Read(pszTxt, nLen);
sRegionScrp = CString(pszTxt, (int)nRead);
delete [] pszTxt; delete [] pszTxt;
file.Close(); file.Close();
+7 -3
View File
@@ -951,11 +951,15 @@ void CDGJMDlg::OnBnClickedBtaddtodb()
if (file.Open(sFullPath,CFile::modeRead)) if (file.Open(sFullPath,CFile::modeRead))
{ {
ULONGLONG dwFileLength = file.GetLength(); ULONGLONG dwFileLength = file.GetLength();
char* pszTxt = new char[dwFileLength]; int nLen = (int)dwFileLength;
file.Read(pszTxt,dwFileLength); // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读
char* pszTxt = new char[nLen + 1];
::memset(pszTxt, 0, nLen + 1);
sRegionScrp = pszTxt; UINT nRead = file.Read(pszTxt, nLen);
sRegionScrp = CString(pszTxt, (int)nRead);
delete [] pszTxt; delete [] pszTxt;
file.Close(); file.Close();
@@ -9418,11 +9418,15 @@ bool FormatScriptFromSection(CString& sScr,STSection* pSection)
if (file.Open(sFullPath,CFile::modeRead)) if (file.Open(sFullPath,CFile::modeRead))
{ {
ULONGLONG dwFileLength = file.GetLength(); ULONGLONG dwFileLength = file.GetLength();
char* pszTxt = new char[dwFileLength]; int nLen = (int)dwFileLength;
file.Read(pszTxt,dwFileLength); // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读
char* pszTxt = new char[nLen + 1];
::memset(pszTxt, 0, nLen + 1);
sRegionScrp = pszTxt; UINT nRead = file.Read(pszTxt, nLen);
sRegionScrp = CString(pszTxt, (int)nRead);
delete [] pszTxt; delete [] pszTxt;
file.Close(); file.Close();
+7 -3
View File
@@ -186,11 +186,15 @@ void CJMDBDlg::OnBnClickedButton2()
if (file.Open(sFullPath, CFile::modeRead)) if (file.Open(sFullPath, CFile::modeRead))
{ {
ULONGLONG dwFileLength = file.GetLength(); ULONGLONG dwFileLength = file.GetLength();
char* pszTxt = new char[dwFileLength]; int nLen = (int)dwFileLength;
file.Read(pszTxt, dwFileLength); // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读
char* pszTxt = new char[nLen + 1];
::memset(pszTxt, 0, nLen + 1);
m_sRegScr = pszTxt; UINT nRead = file.Read(pszTxt, nLen);
m_sRegScr = CString(pszTxt, (int)nRead);
DELETE_ARR_(pszTxt); DELETE_ARR_(pszTxt);
file.Close(); file.Close();
+7 -3
View File
@@ -152,11 +152,15 @@ void CJMSJDlg::OnBnClickedBtaddtodb()
if (file.Open(sFullPath, CFile::modeRead)) if (file.Open(sFullPath, CFile::modeRead))
{ {
ULONGLONG dwFileLength = file.GetLength(); ULONGLONG dwFileLength = file.GetLength();
char* pszTxt = new char[dwFileLength]; int nLen = (int)dwFileLength;
file.Read(pszTxt, dwFileLength); // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读
char* pszTxt = new char[nLen + 1];
::memset(pszTxt, 0, nLen + 1);
sRegionScrp = pszTxt; UINT nRead = file.Read(pszTxt, nLen);
sRegionScrp = CString(pszTxt, (int)nRead);
DELETE_ARR_(pszTxt); DELETE_ARR_(pszTxt);
file.Close(); file.Close();