There are two ways to solve this that I can think of:
- Put the length of the uncompressed data in front of the compressed data. Then, when you're decompressing, count how many characters you have decompressed and stop after the right number.
- Put a special end symbol into your huffman tree that you only use at the end of the file. Then, when uncompressing, stop when you see that symbol.