-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
force casting Vec<T> to &[T] in Table::AsRef is causing trouble #145
Comments
More info:
|
I have the same problem, see here: NNPDF/pineappl#195. |
Also, the signature So there's no way to fix it without breaking change, unless you leak memory indefinitely consider following code: #[test]
fn doom() {
let s: super::TableSlice;
{
let t = Table::new();
s = t.as_ref().clone();
}
println!("{:?}", s);
} This 100% safe rust will lead to segfault |
@david0u0 Would replacing |
@cschwan I think it won't compile, it will contradict the definition of |
+1 to this issue -- the following minimal test is leading to segfaults on nightly (and confirmed fixed by #146)
|
That entire function is a rats nest of undefined behavior. First, casting a reference to a mut reference is undefined behavior, you can easily get into a situation where you have both a You can easily fix this by changing to something like fn as_ref(&self) -> &TableSlice<'a> {
TableSlice {
format: &*self.format,
titles: &*self.titles,
rows: self.rows.as_slice()
}
} |
Hey lovely Op, could you please do a I'll merge a fix for 1.0.0 - need to bring other stuff up-to-date as well. Mark as fixed in 1.0.0 - pondering whether i should bother with a pre-release given a breaking change Closing this when the release is out in crates.io and advisory is out. |
@pinkforest now that the PR is merged, is it still required to mark it as unsound? |
Yes. All the older version need to be marked as such in crates.io and get people moving to 1.0.0. I have some work to do to get to is-terminal and termcolor and do some lotto for MSRV |
I create a PR at rustsec/advisory-db#1503 |
0.10.0 Released and advisory is out 🥳 (I thought 1.0.0 was too premature) |
Summary: `prettytable-rs-0.8.0` has unsafe code ([phsym/prettytable-rs#145][]) that is failing the sanitizers. This is fixed in `prettytable-rs-0.10.0`. Updating `prettydiff` as well because it too depends on `prettytable-rs-0.8.0`. [phsym/prettytable-rs#145]: phsym/prettytable-rs#145 Reviewed By: dtolnay Differential Revision: D43107083 fbshipit-source-id: a7887669201cab5fcf836bd0ed9d14c71180d92b
Summary: `prettytable-rs-0.8.0` has unsafe code ([phsym/prettytable-rs#145][]) that is failing the sanitizers. This is fixed in `prettytable-rs-0.10.0`. Updating `prettydiff` as well because it too depends on `prettytable-rs-0.8.0`. [phsym/prettytable-rs#145]: phsym/prettytable-rs#145 Reviewed By: dtolnay Differential Revision: D43107083 fbshipit-source-id: a7887669201cab5fcf836bd0ed9d14c71180d92b
### Description 1. fix chain id and block number in testool. 2. upgrade "prettytable-rs". The current version will [break in future nightly rust](phsym/prettytable-rs#145). ### Issue Link [_link issue here_] ### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Contents - [_item_] ### Rationale [_design decisions and extended information_] ### How Has This Been Tested? [_explanation_] <hr> ## How to fill a PR description Please give a concise description of your PR. The target readers could be future developers, reviewers, and auditors. By reading your description, they should easily understand the changes proposed in this pull request. MUST: Reference the issue to resolve ### Single responsability Is RECOMMENDED to create single responsibility commits, but not mandatory. Anyway, you MUST enumerate the changes in a unitary way, e.g. ``` This PR contains: - Cleanup of xxxx, yyyy - Changed xxxx to yyyy in order to bla bla - Added xxxx function to ... - Refactored .... ``` ### Design choices RECOMMENDED to: - What types of design choices did you face? - What decisions you have made? - Any valuable information that could help reviewers to think critically
The compiler version: rustc 1.67.0-nightly (c090c6880 2022-12-01)
As shown in the image in gdb:
Table
TableSlice
, returned byTable::AsRef
They have identical pointer value, 0x7ffffff782e0, but the
rows
field in them are in different address.rows
ofTable
is the correct one, whilerows
ofTableSlice
contains random data.Further more, the
rows
ofTableSlice
has length = 93825009397280 (!!!).The cause is in the implementation of
Table::AsRef
. It force casts a&Table
into&TableSlice
, and when the layout of these two types are not the same, it'll cause trouble.The text was updated successfully, but these errors were encountered: