stack overflow

My program is a decompression routine used to decompress compressed art. The problem is that when I try to decompress any compressed art with more than 0xEFF bytes I get this error. Anything below 0xEFF bytes decompresses perfectly. Anyway to fix this.

First-chance exception at 0x10240a97 in EPSDec.exe: 0xC00000FD: Stack overflow.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include<iostream>
#include<fstream>

using namespace std;

void loc_2AD6();
void loc_2B34();
void loc_2AEE();
void loc_2B14();
void loc_2B02();
void sub_2ABC();

fstream a1("ESPArt.bin", ios::in | ios::binary);
fstream a2("ArtDec.bin", ios::out | ios::in | ios::binary |ios::trunc);

//Global Variables

int d4;
unsigned long length1;
unsigned short d5;
unsigned char d5Temp;
unsigned short d6Temp;
unsigned short d52;
unsigned char d6;
unsigned char d7;
unsigned short BIT5;
unsigned short BIT6;
unsigned short SIZECOMPRESS;
unsigned char byte_value;
unsigned char CompByte1;
unsigned char CompByte3;
int length;
long offset;
long pos8;
long posA2;
long posA22;
long pos3;
/////////////////////////////////////////////////

int main(){
cout  <<  "Enter Offset ";
cin >> hex >> offset;
a1.seekg (offset);
SIZECOMPRESS = a1.get()<< 8;
SIZECOMPRESS |= a1.get();
pos8 = a1.tellg();
pos8 = pos8+SIZECOMPRESS;
{sub_2ABC();}}
////////////////////////////////////////////////
void sub_2ABC(){
//a1.seekg (0, ios::cur);
length1 = a1.tellg();
if(length1 == pos8)
a2.close();
else goto
CONT;
CONT:
d5Temp = a1.get();
SIZECOMPRESS--;
d5 = d5 & 0xFF00 | d5Temp;
if(d5 >= 0xFF80)
{loc_2B14();}
else goto
Continue;
Continue:
BIT5 = d5 & 0x20;
BIT6 = d5 & 0x40;
if(BIT5 != 0x0)
{loc_2AD6();}
else if(BIT6 == 0x0)
{loc_2B34();}
else
{loc_2AEE();}
}
/////////////////////////////////////////////////
void loc_2AD6(){
BIT6 = d5 & 0x40;
if(BIT6 != 0x0)
{loc_2B02();}
else goto
Continue;
Continue:
d5 =d5 & 0x1f;
d5++;
d6 = a1.get();
SIZECOMPRESS--;
do{
a2.put(d6);
d5--;
}while(d5 != 0xffff);
{sub_2ABC();}
}
/////////////////////////////////////////////////
void loc_2AEE(){
d5 = d5 & 0x1f;
d5++;
d6 = a1.get();
SIZECOMPRESS--;
d7 = a1.get();
SIZECOMPRESS--;
do{
a2.put(d6);
a2.put(d7);
d5--;
}while(d5 != 0xFFFF);
{sub_2ABC();}
}
/////////////////////////////////////////////////
void loc_2B02(){
//d5Temp = d5 & 0x0000 | d5;
d5 = d5 & 0x1f;
d5++;
d6 = a1.get();
SIZECOMPRESS--;
CompByte1;
do{
a2.put(d6);
CompByte1 = a1.get();
SIZECOMPRESS--;
a2.put(CompByte1);
d5--;
}while (d5 != 0xFFFF);
{sub_2ABC();}
}
/////////////////////////////////////////////////
void loc_2B14(){
d6 = d5;
d5 = d5 & 0xFF00 | ((d5 & 0xFF) >> 2);
d5 = d5 & 0x1f;
d5++;
//unsigned short d6Temp;
d52 =d5;
d6Temp= d6 << 8;
d6Temp = d6Temp & 0xFF00 | (unsigned char) a1.get();
d6Temp = d6Temp & 0x3ff;
d6Temp++;
do{
posA2 = a2.tellg();/// Get First-chance exception at 0x10240a97 in EPSDec.exe: 0xC00000FD: Stack overflow.
posA22 = posA2;
posA22 = posA22 - d6Temp;
a2.seekp (posA22);
CompByte1 = a2.get();
a2.seekp (posA2);
a2.put (CompByte1);
d5--;
}while(d5 != 0xFFFF);
{sub_2ABC();}}
/////////////////////////////////////////////////
void loc_2B34(){
pos3 = a2.tellg();
d5 = d5 & 0x1f;
//CompByte3;
do{
CompByte1=a1.get();
SIZECOMPRESS--;
a2.put(CompByte1);
d5--;
}while(d5 != 0xFFFF);
{sub_2ABC();}
}
Last edited on
Unfortunately, your going to have to trace through the execution with a debugger and some breakpoints to try and isolate th section of code causing a problem. Then we maybe able to help you.
closed account (z05DSL3A)
Any chance of formatting your code, it is quite hard to follow?
Never mind I fixed it. Seems sub_2ABC was called recursively. I've edited so the whole routine is a single function and used goto to branch
1
2
3
4
5
if(BIT6 != 0x0) {
 loc_2B02();
} else goto
 Continue;
Continue:


This piece of code scares me.
It looks like those functions are calling each other in a very strange way- I don't any of them are managing to return at all.

The last line of all the functions (except sub_2ABC )is a call to sub_2ABC() .

So:
1.Main calls Sub_2ABC()
2. sub_2ABC() which at at some point will call one of the other functions.
3. All of the other functions end in a call back to sub_2ABC() - so we are back to step 2.

stack overflow.


Edit: I need to type faster.
Last edited on
Topic archived. No new replies allowed.