Title: serialize19::ReadArchive: how to catch memory read access violation · Issue #6 · basicpp/co-cpp19 · GitHub
Open Graph Title: serialize19::ReadArchive: how to catch memory read access violation · Issue #6 · basicpp/co-cpp19
X Title: serialize19::ReadArchive: how to catch memory read access violation · Issue #6 · basicpp/co-cpp19
Description: I'm using serialize19 to create and load binary files of structured data. But if the file format changes, e.g. because data members have been added / removed, or if the file gets corrupted in some way, the archive reader might cause a re...
Open Graph Description: I'm using serialize19 to create and load binary files of structured data. But if the file format changes, e.g. because data members have been added / removed, or if the file gets corrupted in some ...
X Description: I'm using serialize19 to create and load binary files of structured data. But if the file format changes, e.g. because data members have been added / removed, or if the file gets corrupted in s...
Opengraph URL: https://github.com/basicpp/co-cpp19/issues/6
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"serialize19::ReadArchive: how to catch memory read access violation","articleBody":"I'm using serialize19 to create and load binary files of structured data.\r\n\r\nBut if the file format changes, e.g. because data members have been added / removed, or if the file gets corrupted in some way, the archive reader might cause a read access exception which can't be caught without messing with signal handlers.\r\n\r\n=> is there a clean and reliable way to detect and handle this condition without application crash?\r\n\r\n```\r\n#include \"serialize19/ReadArchive.h\"\r\n#include \"serialize19/dynamicWrite.h\"\r\n#include \"serialize19/serialize.std_string.h\"\r\n\r\nstruct OldFileFormat\r\n{\r\n int a{};\r\n int b{};\r\n std::string s{};\r\n};\r\n\r\nstruct NewFileFormat\r\n{\r\n int a{};\r\n int b{};\r\n int c{};\r\n std::string s{};\r\n};\r\n\r\ntemplate\u003cclass A>\r\nvoid serialize(A& a, OldFileFormat& x)\r\n{\r\n serialize(a, x.a);\r\n serialize(a, x.b);\r\n serialize(a, x.s);\r\n}\r\n\r\ntemplate\u003cclass A>\r\nvoid serialize(A& a, NewFileFormat& x)\r\n{\r\n serialize(a, x.a);\r\n serialize(a, x.b);\r\n serialize(a, x.c);\r\n serialize(a, x.s);\r\n}\r\n\r\nvoid main()\r\n{\r\n OldFileFormat old_data{1, 2, \"test\"};\r\n\r\n const auto buffer_old = serialize19::dynamicWrite(old_data); \r\n\r\n // the buffer contents usually get saved into a binary file:\r\n // std::ofstream fout{filename, std::ios::binary};\r\n // fout.write(reinterpret_cast\u003cconst char*>(slice.begin()), slice.count());\r\n //\r\n // ... and later on we read the file back into a buffer slice via\r\n // std::ifstream fin{filename, std::ios::binary};\r\n // const auto file_buffer = std::vector\u003cuint8_t>{std::istreambuf_iterator(fin), {}}\r\n // const auto file_buffer_slize = serialize19::BufferSlice{file_buffer.data(), file_buffer.size()});\r\n //\r\n // here we just skip this step and hand over the already existing buffer slice \r\n\r\n auto reader = serialize19::ReadArchive{buffer_old.slice()};\r\n NewFileFormat new_data;\r\n\r\n try\r\n {\r\n serialize(reader, new_data);\r\n }\r\n catch (const std::exception& ex)\r\n {\r\n // We want to catch all file read exceptions in a clean way but there is only a hardware exception being thrown which requires dirty signal handler\r\n }\r\n}\r\n```","author":{"url":"https://github.com/fred777","@type":"Person","name":"fred777"},"datePublished":"2023-05-24T16:17:35Z","url":"https://github.com/basicpp/co-cpp19/issues/6"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:591a9d48-cb40-01c5-507e-14acb721a6d0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA00:29A20E:2CEB40B:3D5D6D8:6B005BB2 |
| html-safe-nonce | aac23e57f473ca6a5e20ee9bdad3c4810ad499d24fa9a4af531cda289f476fe6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTAwOjI5QTIwRToyQ0VCNDBCOjNENUQ2RDg6NkIwMDVCQjIiLCJ2aXNpdG9yX2lkIjoiMjgzMzg3MjU1MjQ0MTQzNzEwNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4a89d16e3f81bbf403e10219a7069ef37f062bbb399269353ea864326f5e8d10 |
| hovercard-subject-tag | issue:1724352391 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/basicpp/co-cpp19/6/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2880fcd52ca57cf1cb6b00d8da9265d818c935798a66e5a8d5535fde93271b3d/basicpp/co-cpp19/issues/6 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2880fcd52ca57cf1cb6b00d8da9265d818c935798a66e5a8d5535fde93271b3d/basicpp/co-cpp19/issues/6 |
| og:image:alt | I'm using serialize19 to create and load binary files of structured data. But if the file format changes, e.g. because data members have been added / removed, or if the file gets corrupted in some ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fred777 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 29be975efff6507a5d135de9c7d634cf7ff8f0c55222a64386ab3202209aaf73 |
| turbo-cache-control | no-preview |
| go-import | github.com/basicpp/co-cpp19 git https://github.com/basicpp/co-cpp19.git |
| octolytics-dimension-user_id | 46325550 |
| octolytics-dimension-user_login | basicpp |
| octolytics-dimension-repository_id | 267431850 |
| octolytics-dimension-repository_nwo | basicpp/co-cpp19 |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 267431850 |
| octolytics-dimension-repository_network_root_nwo | basicpp/co-cpp19 |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | eacd927ba6112e3b01ba99c762bd699a4a4f5df7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width