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

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


CInternetFile::ReadString bug?

Jim McCabe -- jmccabe@mail.portup.com
Friday, August 02, 1996

Environment:  Win95, MSVC 4.2, Win95 winsock,
              wininet.dll (06/17/96 11:53a;  286,784 bytes)

I just installed MSVC 4.2 and tried compiling the TEAR sample.  This is an MFC
console program which downloads a web page and displays the source to stdout.

The program has a problem, and it seems to be a bug in MFC
CInternetFile::ReadString.  The first time the function is called, it realizes
it has no buffer and does the following:

a) CInternetFile attempts to allocate a buffer, size 4096, and succeeds
b) a call is made to InternetReadFile (WinInet.DLL), reading the requested
   data, and succeeds

Then, the function leaves its new-buffer code and AGAIN calls
InternetReadFile, apparently unaware that it has already called it.  This
results in lost data, the symptoms of which depend on the size of the web
page:

c) If the web page was small enough to get transmitted in the first
   InternetReadFile call, the next InternetReadFile call returns end-of-file
   and ReadString nulls the buffer that was correctly filled in step (b)
d) If the web page was larger than the initial request, subsequent calls
   seem to work properly, except that the first burst of data from step
   (b) is overwritten and lost.

This really surprised me, not only because ReadString is such a fundamental
and often-used routine for CInternetFile, but also because net classes are one
of the big new features of this release -- you'd think it would have been
tested before cutting the disc.  Then again, I can recall several times in the
past when I thought I found a bug in Windows or MFC and it turned out to be my
fault, so I'm wondering, has anyone else seen this behavior?

Is there a patch for this, or should I rebuild MFC with my own fix?

Thanks,

Jim
jmccabe@mail.portup.com  -  http://www.portup.com/~jmccabe



Mike Blaszczak -- mikeblas@nwlink.com
Tuesday, August 06, 1996

[Mini-digest: 2 responses]

At 02:01 PM 8/2/96 -0400, you wrote:

>This really surprised me, not only because ReadString is such a fundamental
>and often-used routine for CInternetFile, but also because net classes are one
>of the big new features of this release -- you'd think it would have been
>tested before cutting the disc. 

Unfortunately, the unset buffer case escaped me and the tester I was working
with. The problem is fixed in the upcoming patch release for MFC, which will
be released a week or two after the ActiveX SDK itself finally releases.

>Is there a patch for this, or should I rebuild MFC with my own fix?

I'd recommend using a zero-length buffer and waiting for the patch:
rebuilding MFC for a problem that'll be fixed within a month is not
worth the trouble of redistributing and installing and tracking and
deleting separately named libraries.

.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.

-----From: kmg@gregcons.com (Kate Gregory)

>The program has a problem, and it seems to be a bug in MFC
>CInternetFile::ReadString.  The first time the function is called, it realizes
>it has no buffer 

I just ran across the same thing. My workaround was to call
SetReadBufferSize(4096) before calling ReadString. Then it never
"realizes it has no buffer." 

Kate
-- 
Kate Gregory, kate@gregcons.com    www.gregcons.com
Gregory Consulting: programming, training, and advice
Watch for my completely new edition of Using Visual C++ this fall...





| Вернуться в корень Архива |