boostorg / boostorg/iostreams

Reading file in chunks using boost::iostreams::mapped_file_source crashes on Windows

Open
#74 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
48
Forks
124
PR merge metrics
No merged PRs in 30d

Description

I wasted a few hours wondering and trying to fix a bug which caused my application to crash the moment I tried to read the 2nd chunk of a file. The same code runs just fine on `Linux` but does not on `Windows`.

Here is the code snippet I'm using:

```
boost::iostreams::mapped_file_source read_bytes(const char *file_path,
unsigned_value offset, unsigned_value length) {
iostreams::mapped_file_params parameters;
parameters.path = file_path;
parameters.length = static_cast(length);
parameters.flags = iostreams::mapped_file::mapmode::readonly;
parameters.offset = static_cast(offset);

boost::iostreams::mapped_file_source file;

file.open(parameters);

if (file.is_open()) {
return file;
}

printf("Failed to open file\n");
exit(EXIT_FAILURE);
}
```

This is the exception `Visual Studio` showed me:

`Unhandled exception at 0x00007FFD7AFBA388 in PointerSearcher.exe: Microsoft C++ exception: boost::wrapexcept at memory location 0x0000003034FCF270.`

I'm pretty sure I didn't mess anything up since the behavior of `Boost` should be identical on all platforms and I'm using an `offset` and a `length` to read chunks from a file.

Thank you.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.