Comments (4)
Good points. Some thoughts:
- The root cause of #10 was not really forgetting to overwrite an element of the buffer. Claxon enforces that by writing to the elements of
slice::iter_mut
. This is an opt-in kind of thing; I suspect it would be possible to build something safer at no additional runtime cost, but eveniter_mut
is a lot better than manual loop counters and indexing already. - The real issue of #10 was slicing the buffer in such a way that the parts no longer covered the entire buffer. This could have been avoided by using
split_at_mut
orchunks_mut
.
Thinking out loud here: perhaps it would be possible to have a kind of must-write slice that must be written entirely, which can be split up with methods like split_at
, and which must be filled with a method that takes a closure to produce the value, so all values elements are filled. The tricky part for Claxon is that after filling it we do want a mutable slice (to add predictions to the residuals). A method fill(self, F: FnMut() -> T) -> &mut [T]
would work for one slice, but if these were split from a bigger must-write slice, then we can no longer convert the mutable slices back into one mutable slice ... I suspect it might be possible with more closures, analogous to the scoped threadpool API, but that could become hairy.
Also, while zeroing is a valuable defence against the possibility of exposing uninitialized memory in the presence of bugs, it does not prevent the real bug, which was not overwriting the entire buffer. A solution that can do the latter would be nice.
from claxon.
Is there a particular reason why you went with slicing the buffer and passing the slices to decoding functions instead of passing the buffer to decoding functions and using buffer.extend()
or similar? Extend trait for reference
from claxon.
I've rewritten passing around a slice of uninitalized memory into appending to a Vec. This has killed off some fiddly math in the process. The result can be found here: https://github.com/Shnatsel/claxon/tree/safe-and-sliceless
There's just one problem: it fails some decoding tests, and I'm not sure how to isolate the problem because decode_* functions do not have unit tests for them.
from claxon.
Closed by fec2467.
from claxon.
Related Issues (19)
- version of hound required by claxon does not compile HOT 3
- Contents of uninitialized memory are leaked into the output on malformed inputs HOT 9
- Some FLAC files don't decode because LPC order > 12 is not supported HOT 6
- Support reading flac tag HOT 2
- Emtpy Vorbis Comment HOT 7
- How to use in async code HOT 2
- Consider adding encoding support HOT 1
- Reading on uninitialized memory may cause UB HOT 6
- MSRV for this crate? HOT 2
- A blueprint for seeking feature HOT 6
- Frame with block size shorter than 16 samples HOT 2
- Reading undecoded FLAC frames HOT 3
- Last call on FLAC specification HOT 2
- Frame CRC mismatch HOT 2
- Support alternative containers HOT 5
- Issues with privacy HOT 7
- About the metadata issue HOT 2
- FLAC file reading performance HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from claxon.