video-audio / va-ts Goto Github PK
View Code? Open in Web Editor NEWMPEG-TS muxer/demuxer library for Rust
License: MIT License
MPEG-TS muxer/demuxer library for Rust
License: MIT License
Howdy,
Not sure if any of the MPEGTS muxing is working from what I can see in the code?
If so, and I'm missing something, do you have a working example of muxing video, audio and producing the SI tables into the TS stream?
Can the muxer operating via fifo's and not rely an files as input and output?
Cheers
Hello ๐ฆ , we (Rust group @sslab-gatech) found an undefined-behavior issue in this crate while scanning Rust code on crates.io for potential vulnerabilities.
Send
is unconditionally implemented for Demuxer
, so that it is possible for a non-Send implementor of DemuxerEvents
trait to be sent across thread boundaries.
unsafe impl<T> Send for Demuxer<T> where T: DemuxerEvents {}
Here is a simple program where Demuxer
is used to move a MutexGuard
(!Send
object) to another thread.
It is also possible to create data races by inserting non-Send types like Rc
or Cell
into Demuxer
(which is not demonstrated in the example code below).
use va_ts::{Demuxer, DemuxerEvents, SubtableID, DemuxedPacket, DemuxedTable};
use std::sync::{Mutex, MutexGuard};
use std::thread::{self, ThreadId};
use std::ops::Drop;
struct X(MutexGuard<'static, u64>, ThreadId);
impl DemuxerEvents for X {
fn on_table(&mut self, _: SubtableID, _: &DemuxedTable) { }
fn on_packet(&mut self, _: &DemuxedPacket) { }
}
impl Drop for X {
fn drop(&mut self) {
// `MutexGuard` must not be dropped from a thread that didn't lock the `Mutex`.
//
// If a thread attempts to unlock a Mutex that it has not locked, it can result in undefined behavior.
// (https://github.com/rust-lang/rust/issues/23465#issuecomment-82730326)
assert_eq!(self.1, thread::current().id());
}
}
fn main() {
let static_mutex = Box::leak(Box::new(Mutex::new(0xbeefbeef_u64)));
// MutexGuard is `!Send`
let mutex_guard = static_mutex.lock().unwrap();
let tid = thread::current().id();
let demuxer = Demuxer::new(X(mutex_guard, tid));
std::thread::spawn(move || {
let demuxer = demuxer;
// demuxer is dropped here, along with `MutexGuard`.
}).join().unwrap();
}
Adding a trait bound T: Send
as below will allow the compiler to prevent Demuxer
from moving !Send
types across thread boundaries.
unsafe impl<T> Send for Demuxer<T> where T: DemuxerEvents + Send {}
Thank you for reviewing this issue ๐
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
Cargo.toml
chrono ~0.4.31
encoding_rs ~0.8.33
clap ~4.3.0
url ~2.5.0
dockerfiles/docker-compose.yml
dockerfiles/build-rs/Dockerfile
debian 12
dockerfiles/tsplay/Dockerfile
debian 12
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.