2

Let's say I'm sending a multipart request (or response). I need to choose a multipart boundary which does not appear in any of my payloads. However, my payloads are large binary files and I am streaming them to the destination. I want to avoid streaming them twice - once to scan for the boundary and one to stream out.

So my question is: is it possible to escape the boundary if it appears in the payload? If so, how?

2 Answers 2

3

Don't Panic. Your boundary can be up to 70 characters long. If you go with that maximum and randomly generate it out of characters and numbers you'll have 62⁷⁰ possible combinations for each position in a file. Chance of having the same sequence of bytes in your binary files is so infinitesimal that it shouldn't bother your sleep at all 😀. The probability of collision in a 1GB file is roughly 1-((1-(1/(62^70)))^(10^9)) ~= 3.4*10⁻¹¹⁸. Human brain can't really fathom how small that number is. For comparison the number of atoms in our universe is estimated to be ~ 10⁸⁰.

Sign up to request clarification or add additional context in comments.

Comments

0

No, it's not possible; you need to either scan, or live with potential failures.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.