15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Archive bug?

Thanos Kontos -- tk4n@hti.net
Friday, April 05, 1996

VC++ 4.1/MFC 4.1/Windows95 or NT

I believe there is a bug in arccore. When a trancated file is read, MFC
ASSERTs. It should throw an exception (shouldn't it?).

This problem can be demonstrated by an AppWizard generated application,
where the serialize code is as code:

...
void CArcDoc::Serialize(CArchive& ar)
{
	DWORD	dw = 0;
	WORD	w = 0;
	if (ar.IsStoring())
	{
		ar << dw << w;		// Writes 3 bytes
	}
	else
	{
		ar >> dw;
		ar >> dw;		// <---- Did not get expected endOfFile Exception here
	}
}
...

To work around the problem, I had to modify the 'arccore.cpp' as follows:

line 689:
	// m_lpBufMax -= nUnused; // TK: Removed
	m_lpBufMax = m_lpBufStart+nUnused; // TK: Added

line 693:
	// UINT nRead = nUnused; // TK: Removed
	UINT nRead = 0; // TK: Added




Dan Kirby -- dkirby@accessone.com
Saturday, April 06, 1996

Hi,
You are correct.  This is a bug.

Your fix is fine.  Note that it will not cause the exception to be thrown 
on line 724 where the code reads:

	// not enough data to fill request?
	if ((UINT)(m_lpBufMax - m_lpBufCur) < nBytesNeeded)
		AfxThrowArchiveException(CArchiveException::endOfFile);

Instead, your change will cause the exception to be thrown in the 
CFile::Read.

Another interesting thing to note is that there will be times when the 
exception will get thrown OK depending upon what you are storing and 
reading. So for example, if you modify your example slightly:

void CArchbugDoc::Serialize(CArchive& ar)
{
	DWORD	dw = 0;
	WORD	w = 0;
    BYTE    ch;
	if (ar.IsStoring())
	{
		ar << dw <> dw;
		ar >> dw;		// <---- Did not get expected endOfFile Exception here
	}

}

This will thrown the eof exception.

--dan

----------
From: 	Thanos Kontos[SMTP:tk4n@hti.net]
Sent: 	Friday, April 05, 1996 10:08 AM
To: 	'MFC List'
Subject: 	Archive bug?

VC++ 4.1/MFC 4.1/Windows95 or NT

I believe there is a bug in arccore. When a trancated file is read, MFC
ASSERTs. It should throw an exception (shouldn't it?).

This problem can be demonstrated by an AppWizard generated application,
where the serialize code is as code:

...
void CArcDoc::Serialize(CArchive& ar)
{
	DWORD	dw = 0;
	WORD	w = 0;
	if (ar.IsStoring())
	{
		ar << dw << w;		// Writes 3 bytes
	}
	else
	{
		ar >> dw;
		ar >> dw;		// <---- Did not get expected endOfFile Exception here
	}
}
...

To work around the problem, I had to modify the 'arccore.cpp' as follows:

line 689:
	// m_lpBufMax -= nUnused; // TK: Removed
	m_lpBufMax = m_lpBufStart+nUnused; // TK: Added

line 693:
	// UINT nRead = nUnused; // TK: Removed
	UINT nRead = 0; // TK: Added





begin 600 WINMAIL.DAT
M>)\^(A %`0:0" `$```````!``$``0>0!@`(````Y 0```````#H``$(@ <`
M& ```$E032Y-:6-R;W-O9G0@36%I;"Y.;W1E`#$(`0V ! `"`````@`"``$$
MD 8`1 (```(````,`````P``, ,````+``\.``````(!_P\!````/P``````
M``"!*Q^DOJ,0&9UN`-T!#U0"`````&UF8RUL0&YE=&-O;2YC;VT`4TU44 !M
M9F,M;$!N971C;VTN8V]M```>``(P`0````4```!33510`````!X``S !````
M$0```&UF8RUL0&YE=&-O;2YC;VT``````P`5# $````#`/X/!@```!X``3 !
M````$P```"=M9F,M;$!N971C;VTN8V]M)P```@$+, $````6````4TU44#I-
M1D,M3$!.151#3TTN0T]-`````P``.0`````+`$ Z`0````(!]@\!````! ``
M``````,-`````P``, 0````+``\.`0````(!_P\!````-P````````"!*Q^D
MOJ,0&9UN`-T!#U0"```!`'1K-&Y :'1I+FYE= !33510`'1K-&Y :'1I+FYE
M= ``'@`", $````%````4TU44 `````>``,P`0````T```!T:S1N0&AT:2YN
M970``````P`5# $````#`/X/!@```!X``3 !````#P```"=T:S1N0&AT:2YN
M970G```"`0LP`0```!(```!33510.E1+-$Y 2%1)+DY%5 ````,``#D`````
M"P! .@`````"`?8/`0````0````````$`@'Y#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