take a piece of wire and stick thru the hole and get it flush or mark it so when you pull it out you will know how deep the hole is. buy at least a half inch extra than what it measures because usually the rails are thicker in some spots than in others.
when it comes to #8 or #10 stainless bolts, I always buy in bulk and always buy lots of extra length. (I only buy 1", 2.5", and 4") the extra cost is insignificant and the longer bolts will be more versatile.
after installing them its very easy and simple to grab the extra length with pliers and work it a couple times. it snaps right off at the nut and the nut can still be removed if necessary, but it wont fall off due to any vibration over time as can happen with an unsecured nut. especially on rubrails. I usually always wipe a dab of silicone on the nut/threads after tightening anyway to insure it stays tight. Im sorry i cant give you an exact length for your project. good luck.