from typing import List


def get_ij_bbox(subdataset, geom) -> List[int]:
    """Clips the subdataset with the geometry.

    Args:
        subdataset: An open rasterio.io DatasetReader.
        geom: A shapley geometry object.

    Returns:
        The corresponding bbox."""
    x_min, y_min, x_max, y_max = geom.bounds
    row_start, col_start = subdataset.index(x_min, y_max)
    row_start, col_start = max(0, row_start), max(0, col_start)
    row_stop, col_stop = subdataset.index(x_max, y_min)
    row_stop = min(subdataset.height - 1, row_stop)
    col_stop = min(subdataset.width - 1, col_stop)
    return [row_start, col_start, row_stop, col_stop]