Skip to content

Harden TIFF parsing/index bounds and split Python binding concerns from core library#3

Merged
rhayman merged 3 commits into
masterfrom
copilot/implement-codebase-improvements
May 21, 2026
Merged

Harden TIFF parsing/index bounds and split Python binding concerns from core library#3
rhayman merged 3 commits into
masterfrom
copilot/implement-codebase-improvements

Conversation

Copilot AI commented May 21, 2026

Copy link
Copy Markdown
Contributor

This change addresses three coupled issues: unsafe parsing/index assumptions in TIFF/log handling, tight Python-binding coupling in the C++ core API, and stale repository/build metadata. The update hardens input handling and frame/channel indexing while separating core library concerns from Python interop.

  • Parsing and index hardening

    • Made channel metadata parsing resilient to malformed/partial header tokens (LUT, offsets, saved channels).
    • Replaced direct numeric conversions with guarded parsing paths for frame number/timestamp extraction.
    • Added explicit bounds validation for frame/channel mapping in setChannel, readFrame, writeFrame, tail, and saveTiffTail.
    • Added interpolation safeguards when nearest-index lookup returns invalid positions.
  • Core/Python decoupling

    • Removed Python/carma types from the public core API (include/ScanImageTiff.h).
    • Core now exposes Armadillo-native signatures (e.g., readFrame -> arma::Mat<int16_t>, tail -> arma::Cube<int16_t> tuple).
    • Moved numpy/arma conversion to the pybind layer (src/ScanImageTiffPy.cpp) via binding lambdas.
  • Build graph and stale metadata cleanup

    • Refactored CMake so the core shared library builds independently from Python bindings.
    • Added optional BUILD_PYTHON_BINDINGS flow with explicit dependency failure messaging.
    • Removed obsolete .gitmodules submodule metadata.
    • Removed stale test target source/link wiring tied to old Python-coupled structure.
// Binding layer now owns Python conversion boundary
.def("get_frame", [](twophoton::SITiffIO &self, int frame) {
  auto mat = self.readFrame(frame);      // core returns arma::Mat<int16_t>
  return carma::mat_to_arr(std::move(mat));
})

@rhayman rhayman marked this pull request as ready for review May 21, 2026 11:02
@rhayman rhayman merged commit 54fe886 into master May 21, 2026
1 check passed
@rhayman rhayman deleted the copilot/implement-codebase-improvements branch May 21, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants