Skip to content

Commit 8607212

Browse files
Add guard entry to asin table.
There was a potential off-end access if the operand to asin()/acos() was exactly 1.
1 parent a308e3a commit 8607212

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Diff for: src/Libraries/FIX/Source/MakeTables.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ uint16_t sintab[256+64+1] = {
8484
// Its units are fixangs.
8585
//
8686
// acos(x) = PI/2 - asin(x). (PI/2 is fixang 0x4000)
87+
// Note that there are 130 entries in the table. The asin and acos functions
88+
// will use the low 8 bits to interpolate between entry i and entry i+1: if the
89+
// parameter is exactly 1, this will be asintab[128] and asintab[129].
8790

8891
// indexed by (high 8 bits of (fix >> 2 + 0x4000)
8992
// clang-format off
90-
fixang asintab[128+1] = {
93+
fixang asintab[128+1+1] = {
9194
0xc001, 0xc737, 0xca37, 0xcc87, 0xce7c, 0xd037, 0xd1ca, 0xd33d,
9295
0xd498, 0xd5e0, 0xd716, 0xd840, 0xd95d, 0xda6f, 0xdb78, 0xdc7a,
9396
0xdd73, 0xde67, 0xdf54, 0xe03c, 0xe11e, 0xe1fd, 0xe2d7, 0xe3ad,
@@ -104,7 +107,7 @@ fixang asintab[128+1] = {
104107
0x1b82, 0x1c54, 0x1d2a, 0x1e04, 0x1ee3, 0x1fc5, 0x20ad, 0x219a,
105108
0x228e, 0x2387, 0x2489, 0x2592, 0x26a4, 0x27c1, 0x28eb, 0x2a21,
106109
0x2b69, 0x2cc4, 0x2e37, 0x2fca, 0x3185, 0x337a, 0x35ca, 0x38ca,
107-
0x4000
110+
0x4000, 0x4000
108111
};
109112
// clang-format on
110113

Diff for: src/Libraries/FIX/Source/trigtab.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919
extern uint16_t sintab[256 + 64 + 1];
2020

21-
extern fixang asintab[128 + 1];
21+
extern fixang asintab[128 + 1 + 1];
2222

2323
#define INTEGER_EXP_OFFSET 11
2424
extern uint32_t expinttab[INTEGER_EXP_OFFSET * 2 + 1];

0 commit comments

Comments
 (0)