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: segmentation fault thrown on different layout images #44

Merged
merged 2 commits into from
Sep 28, 2024
Merged
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
2 changes: 1 addition & 1 deletion lib/OSnap_Browser/Zip.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let read_4_bytes_int ic =
let read_string ic len =
let buf = Bytes.create len in
really_input ic buf 0 len;
Bytes.unsafe_to_string buf
Bytes.to_string buf
;;

let int64_of_uint32 n = Int64.(logand (of_int32 n) 0xFFFF_FFFFL)
Expand Down
19 changes: 9 additions & 10 deletions lib/OSnap_Diff/OSnap_Diff.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,23 @@ let diff
if col >= original_image_start
&& col < original_image_end
&& row < original_image.height
then Array1.unsafe_get original_image.image ((row * original_image.width) + col)
then Array1.get original_image.image ((row * original_image.width) + col)
else if col > diff_mask_start && col < diff_mask_end
then (
let diff_pixel =
if row < diff_mask.height
then
Array1.unsafe_get
Array1.get
diff_mask.image
((row * diff_mask.width) + (col - diff_mask_start))
else 0x00000000l
in
if not (Int32.equal diff_pixel 0x00000000l)
then diff_pixel
else (
else if row < original_image.height
then (
let pixel =
Array1.unsafe_get
Array1.get
original_image.image
((row * original_image.width) + (col - diff_mask_start))
|> Int32.to_int
Expand All @@ -105,15 +106,13 @@ let diff
let b = (mono land 0xFF) lsl 16 in
let g = (mono land 0xFF) lsl 8 in
let r = (mono land 0xFF) lsl 0 in
Int32.of_int (a lor b lor g lor r)))
Int32.of_int (a lor b lor g lor r))
else 0x00000000l)
else if col > new_image_start && col <= new_image_end && row < new_image.height
then
Array1.unsafe_get
new_image.image
((row * new_image.width) + (col - new_image_start))
then Array1.get new_image.image ((row * new_image.width) + (col - new_image_start))
else 0x00000000l
in
Array1.unsafe_set complete_image offset fill_with
Array1.set complete_image offset fill_with
done;
free_images ();
Osnap_Diff_Png.PngIo.write_png_bigarray
Expand Down
4 changes: 2 additions & 2 deletions lib/OSnap_Diff/png/Osnap_Diff_Png.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ module IO = struct

let readDirectPixel ~(x : int) ~(y : int) (img : t ImageIO.img) =
let image = (img.image : data) in
Array1.unsafe_get image ((y * img.width) + x)
Array1.get image ((y * img.width) + x)
;;

let setImgColor ~x ~y color (img : t ImageIO.img) =
let image = (img.image : data) in
Array1.unsafe_set image ((y * img.width) + x) color
Array1.set image ((y * img.width) + x) color
;;

let loadImage buffer : t ImageIO.img =
Expand Down
Loading