Skip to content

Issues with IIS ReadFileChunk #28

Closed
@keesspoelstra

Description

@keesspoelstra

Typing this off the top of my head :), so mind any typos.

IIS function HRESULT CMyHttpModule::ReadFileChunk(HTTP_DATA_CHUNK *chunk, char *buf)
fails in the following cases:

  • If the datachunk has an offset it will copy the first bytes of the block read instead of the bytes after the offset. This is behaviour seen in ARR, the cache will store headers and content in one file.
    Fix:
    memcpy(buf, pIoBuffer, bytesRead);
    to
    memcpy(buf, pIoBuffer+dwDataStartOffset, bytesRead);
  • Bytestotal is not honored in byte ranges, files with a byte range ending before EOF will copy to a whole page extra in buf, possibly overwriting other data (small risk if buf is allocated with a multiple of pagesize) bytesRead should be adjusted before the memcpy to stop it from copying the extra bytes.
    The guarding statement checking bytesRead against the length will not work with multiple page reads.
    Fix:
    if (bytesRead > chunk->FromFileHandle.ByteRange.Length.QuadPart) { bytesRead = (DWORD)chunk->FromFileHandle.ByteRange.Length.QuadPart; }
    if ((bytesTotal+bytesRead) > chunk->FromFileHandle.ByteRange.Length.QuadPart) { bytesRead = chunk->FromFileHandle.ByteRange.Length.QuadPart-bytesTotal; }
  • Allocation of the page is implicit, explicitly specifying the pagesize will make the code more robust.

Regards,
Kees

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions