Large POST data is corrupted when using Django/PyISAPIe/IIS

人盡茶涼 提交于 2019-12-06 11:13:57

PyISAPIe author here.

This was fixed in revision 184 in the repository but not in the downloadable release, as discussed on the mailing list.

It addressed a previously documented bug that apparently hasn't received much attention because many users are checking out the source rather than downloading the package. Or, that's my best guess anyway; regardless, I plan to provide a downloadable version of the fixed code.

Thanks for bringing this to my attention so I can be reminded to keep this project's releases in a functioning state.

I dug a little deeper and I think I found the issue.

In PyISAPIe\Readwrite.cpp:

PyISAPIe_Func(DWORD) ReadClient( Context &Ctx, DWORD Length, void *const Data )
{
  if ( !Length )
    Length = Ctx.ECB->cbTotalBytes;

  if ( !Data )
    // Return the size of the the data that would be read
    return min(Length, Ctx.ECB->cbTotalBytes);

  DWORD Ret, Total = 0;

  if ( Length > Ctx.ECB->cbAvailable )
  {
    [...snip...]
  }
  else
  {
    memcpy(Data, Ctx.ECB->lpbData, Length);
    Ctx.ECB->cbTotalBytes -= Length;
    Ctx.ECB->cbAvailable -= Length;
    return Length;
  }

If the method is called repeatedly with Length <= Ctx.ECB->cbAvailable, it seems to always copy the beginning of the Ctx.ECB->lpbData buffer into Data, and not removing that data from the buffer or advancing a pointer. Only when the data is exhausted (cbAvailable == 0) is new data correctly read into Data later in the code.

Still not sure how to fix it, but at least I can work around it by reading in large enough chunks of data so that one chunk will read it all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!