edit: Sorry, I was thinking cartridge length and not projectile length. Here's a couple numbers and a pic that don't really help
My rail mount M203 measures 5.407" barrel to breech face.
The pictured casing is 4.880" long.
another edit:
You might run into a payload mass/velocity/chamber pressure tradeoff that limits you before the projectile length.
I did some napkin math for you:
assuming a solid 60/40 KNO3-sugar smoke mix projectile, 40mmø and 4" long, it'll weigh about 0.53lb
M781 is about 0.39lb at 250ft/s
I've seen reference to some HEDP projectiles at around 0.44lb and 250ft/s
Obviously, increasing mass will require a hotter load to maintain velocity. (Does anyone have max load info they can share
)
Bearing surface,projectile to bore fit, and other things will all have an affect.
I made a lot of assumptions and simplifications, but I hope that's at least helpful as a point of consideration.
Of course, if you're loading cotton balls and packing peanuts, it might not matter much.