Skip to content
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

Fix incomplete attached file problem #1261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions crates/bridge_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,11 @@
rhandle.read_exact(buf).map_err(Error::from)
}

fn input_read_partial(&mut self, handle: *mut InputHandle, buf: &mut [u8]) -> Result<usize> {
let rhandle: &mut InputHandle = unsafe { &mut *handle };
rhandle.read(buf).map_err(Error::from)
}

Check warning on line 680 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L677-L680

Added lines #L677 - L680 were not covered by tests

fn input_getc(&mut self, handle: *mut InputHandle) -> Result<u8> {
let rhandle: &mut InputHandle = unsafe { &mut *handle };
rhandle.getc()
Expand Down Expand Up @@ -1181,6 +1186,9 @@

/// Read data from a Tectonic input handle
///
/// This read corresponds to Rust's read_exact, i.e. it will return exactly the number of requested
/// bytes or error (-1).
///
/// # Safety
///
/// This function is unsafe because it dereferences raw C pointers.
Expand All @@ -1202,6 +1210,32 @@
}
}

/// Read data from a Tectonic input handle
///
/// This read corresponds to Rust's read, i.e. it can return less bytes than requested (and does
/// when buffering)
///
/// # Safety
///
/// This function is unsafe because it dereferences raw C pointers.
#[no_mangle]
pub unsafe extern "C" fn ttbc_input_read_partial(

Check warning on line 1222 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L1222

Added line #L1222 was not covered by tests
es: &mut CoreBridgeState,
handle: *mut InputHandle,
data: *mut u8,
len: libc::size_t,
) -> libc::ssize_t {
let rdata = slice::from_raw_parts_mut(data, len);

Check warning on line 1228 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L1228

Added line #L1228 was not covered by tests

match es.input_read_partial(handle, rdata) {
Ok(size) => size as isize,
Err(e) => {
tt_warning!(es.status, "{}-byte read failed", len; e);
-1
}

Check warning on line 1235 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L1230-L1235

Added lines #L1230 - L1235 were not covered by tests
}
}

Check warning on line 1237 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L1237

Added line #L1237 was not covered by tests

/// Close a Tectonic input file.
#[no_mangle]
pub extern "C" fn ttbc_input_close(
Expand Down
5 changes: 5 additions & 0 deletions crates/bridge_core/support/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@
return ttbc_input_read(tectonic_global_bridge_core, handle, (uint8_t *) data, len);
}

ssize_t
ttstub_input_read_partial(rust_input_handle_t handle, char *data, size_t len)
{
return ttbc_input_read_partial(tectonic_global_bridge_core, handle, (uint8_t *) data, len);

Check warning on line 291 in crates/bridge_core/support/support.c

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/support/support.c#L291

Added line #L291 was not covered by tests
}

int
ttstub_input_getc(rust_input_handle_t handle)
Expand Down
1 change: 1 addition & 0 deletions crates/bridge_core/support/tectonic_bridge_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ size_t ttstub_input_get_size(rust_input_handle_t handle);
time_t ttstub_input_get_mtime(rust_input_handle_t handle);
size_t ttstub_input_seek(rust_input_handle_t handle, ssize_t offset, int whence);
ssize_t ttstub_input_read(rust_input_handle_t handle, char *data, size_t len);
ssize_t ttstub_input_read_partial(rust_input_handle_t handle, char *data, size_t len);
int ttstub_input_getc(rust_input_handle_t handle);
int ttstub_input_ungetc(rust_input_handle_t handle, int ch);
int ttstub_input_close(rust_input_handle_t handle);
Expand Down
2 changes: 2 additions & 0 deletions crates/bridge_core/support/tectonic_bridge_core_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ int ttbc_input_ungetc(ttbc_state_t *es, ttbc_input_handle_t *handle, int ch);
*/
ssize_t ttbc_input_read(ttbc_state_t *es, ttbc_input_handle_t *handle, uint8_t *data, size_t len);

ssize_t ttbc_input_read_partial(ttbc_state_t *es, ttbc_input_handle_t *handle, uint8_t *data, size_t len);

/**
* Close a Tectonic input file.
*/
Expand Down
2 changes: 1 addition & 1 deletion crates/pdf_io/pdf_io/dpx-spc_pdfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@
}
fstream = pdf_new_stream(STREAM_COMPRESS);
while ((nb_read =
ttstub_input_read(handle, work_buffer, WORK_BUFFER_SIZE)) > 0)
ttstub_input_read_partial(handle, work_buffer, WORK_BUFFER_SIZE)) > 0)

Check warning on line 1667 in crates/pdf_io/pdf_io/dpx-spc_pdfm.c

View check run for this annotation

Codecov / codecov/patch

crates/pdf_io/pdf_io/dpx-spc_pdfm.c#L1667

Added line #L1667 was not covered by tests
pdf_add_stream(fstream, work_buffer, nb_read);
ttstub_input_close(handle);
break;
Expand Down