summaryrefslogtreecommitdiff
path: root/plugins/Import/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-05-04 13:59:02 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-05-04 13:59:02 +0300
commit4a615270331b2f9d21fa66814e1ad1ea1d5f91a7 (patch)
tree7afeca1fd2d6208a5549d664205cdc675546ba5c /plugins/Import/src
parent1924b2cadd37cbccbaf819074b07f7e69d560757 (diff)
fix for a major memory leak in mContacts import
Diffstat (limited to 'plugins/Import/src')
-rw-r--r--plugins/Import/src/mcontacts.cpp56
1 files changed, 42 insertions, 14 deletions
diff --git a/plugins/Import/src/mcontacts.cpp b/plugins/Import/src/mcontacts.cpp
index 748881538b..6ac718d878 100644
--- a/plugins/Import/src/mcontacts.cpp
+++ b/plugins/Import/src/mcontacts.cpp
@@ -151,6 +151,35 @@ public:
}
// mcontacts format always store history for one contact only
+ STDMETHODIMP_(LONG) GetBlobSize(MEVENT dwOffset) override
+ {
+ if (INVALID_SET_FILE_POINTER == SetFilePointer(m_hFile, dwOffset, 0, FILE_BEGIN))
+ return 0;
+
+ DWORD dwRead, dwSize;
+ BOOL r = ReadFile(m_hFile, &dwSize, sizeof(dwSize), &dwRead, nullptr);
+ if (!r || dwRead != sizeof(dwSize))
+ return 0;
+
+ SetFilePointer(m_hFile, -4, 0, FILE_CURRENT);
+
+ if (dwSize == sizeof(MC_MsgHeader32)) {
+ MC_MsgHeader32 hdr;
+ r = ReadFile(m_hFile, &hdr, sizeof(hdr), &dwRead, 0);
+ if (!r || dwRead != sizeof(hdr))
+ return 0;
+ return hdr.cbBlob+1;
+ }
+ if (dwSize == sizeof(MC_MsgHeader64)) {
+ MC_MsgHeader64 hdr;
+ r = ReadFile(m_hFile, &hdr, sizeof(hdr), &dwRead, 0);
+ if (!r || dwRead != sizeof(hdr))
+ return 0;
+ return hdr.cbBlob+1;
+ }
+ return 0;
+ }
+
STDMETHODIMP_(LONG) GetContactCount(void) override
{
return 1;
@@ -164,23 +193,24 @@ public:
STDMETHODIMP_(BOOL) GetEvent(MEVENT dwOffset, DBEVENTINFO *dbei) override
{
if (INVALID_SET_FILE_POINTER == SetFilePointer(m_hFile, dwOffset, 0, FILE_BEGIN))
- return 0;
+ return 1;
DWORD dwRead, dwSize;
BOOL r = ReadFile(m_hFile, &dwSize, sizeof(dwSize), &dwRead, nullptr);
if (!r || dwRead != sizeof(dwSize))
- return 0;
+ return 1;
SetFilePointer(m_hFile, -4, 0, FILE_CURRENT);
+ int cbLen;
if (dwSize == sizeof(MC_MsgHeader32)) {
MC_MsgHeader32 hdr;
r = ReadFile(m_hFile, &hdr, sizeof(hdr), &dwRead, 0);
if (!r || dwRead != sizeof(hdr))
- return 0;
+ return 1;
dbei->eventType = hdr.eventType;
- dbei->cbBlob = hdr.cbBlob;
+ cbLen = hdr.cbBlob;
dbei->flags = hdr.flags;
dbei->timestamp = hdr.timestamp;
}
@@ -188,24 +218,22 @@ public:
MC_MsgHeader64 hdr;
r = ReadFile(m_hFile, &hdr, sizeof(hdr), &dwRead, 0);
if (!r || dwRead != sizeof(hdr))
- return 0;
+ return 1;
dbei->eventType = hdr.eventType;
- dbei->cbBlob = hdr.cbBlob;
+ cbLen = hdr.cbBlob;
dbei->flags = hdr.flags;
dbei->timestamp = hdr.timestamp;
}
- else return 0;
+ else return 1;
- if (dbei->cbBlob) {
- dbei->pBlob = (PBYTE)mir_alloc(dbei->cbBlob + 1);
- if (!ReadFile(m_hFile, dbei->pBlob, dbei->cbBlob, &dwRead, 0) || dwRead != dbei->cbBlob) {
- mir_free(dbei->pBlob);
- dbei->pBlob = 0;
+ if (dbei->cbBlob && cbLen) {
+ int copySize = min(cbLen, dbei->cbBlob-1);
+ if (!ReadFile(m_hFile, dbei->pBlob, copySize, &dwRead, 0) || dwRead != copySize)
return 0;
- }
- dbei->pBlob[dbei->cbBlob] = 0;
+ dbei->cbBlob = copySize;
+ dbei->pBlob[copySize] = 0;
}
return 0;