question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Division by zero crash in iOS when resolution is smaller than the specified output resolution

See original GitHub issue

Calling compress on a source video of size 848x480 (as output by Ray-Ban Stories glasses) with a desired output of 1280x720 will yield a division by zero error in the makeVideoBitrate function. Specifically this line:

var remeasuredBitrate:Int = originalBitrate / (min(originalHeight/height,originalWidth/width))

Since originalHeight is an int, and height is a larger int, the result will be 0 (cuz we’re doing integer division), so we’ll end up dividing originalBitrate by 0 and creating a rift in time and space as we know it.

Actually, the entire function is doing some integer math that might have some issues, like:

let compressFactor:Float = 0.8
// a few lines later
remeasuredBitrate = remeasuredBitrate*Int(compressFactor)

Coercing compressFactor into an int is essentially a floor function - the decimal gets rounded down to zero. So this will always guarantee that the remeasuredBitrate is 0.

I’d be pleased to help advise how to fix this up, but as it’s not really documented what this function is supposed to do, it’s a bit tricky to tell what needs to happen solo. Happy to discuss more!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
GrandPoohBearcommented, Dec 8, 2021

Looks good! I’ll update shortly.

0reactions
drash-coursecommented, Dec 28, 2021

You can find a PR for the issue above. https://github.com/Shobbak/react-native-compressor/pull/73

It’s not exactly on topic but I’ll leave it here if someone finds this issue with the same problem as me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Division by zero | Apple Developer Documentation
Division by zero has undefined behavior, and can result in crashes or incorrect program output. Available in Xcode 9 and later.
Read more >
A Divide by Zero results in a crash - Stack Overflow
That the app crashes when you divide by zero is expected behavior. You have to fix the cause of the illegal division. –...
Read more >
How to fix a divide or divide by zero error - Computer Hope
Steps and help with resolving a divide error, divide by zero error, #DIV!0, and related divide errors.
Read more >
AGS 3.5.0 - Patch 9
AGS 3.5.0 has brought a number of completely new features and changed few older things. ... Allow room size to be smaller than...
Read more >
DivideByZeroException Class (System) - Microsoft Learn
The exception that is thrown when there is an attempt to divide an integral or Decimal value by zero.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found