Skip to content

Commit

Permalink
Check properly for permutations whose degree would exceed the
Browse files Browse the repository at this point in the history
internal limit. Document the limit.
  • Loading branch information
stevelinton committed Feb 4, 2016
1 parent 1e3236e commit 06f20be
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/permutat.g
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
## takes <M>4m</M> bytes of storage.
## It can take even more because the internal list has sometimes room for
## more than <M>d</M> images.
## <P/> On 32-bit systems, the limit on the degree of permutations is, for
## technical reasons, <M>2^{{28}}-1</M>.
## On 64-bit systems, it is <M>2^{{32}}-1</M> because only a 32-bit integer
## is used to represent each image internally. Error messages should be given
## if any command would require creating a permutation exceeding this limit.
## <P/>
## The operation <Ref Func="RestrictedPerm"/> reduces the storage degree of
## its result and therefore can be used to save memory if intermediate
Expand Down
3 changes: 3 additions & 0 deletions src/exprs.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,9 @@ Obj EvalPermExpr (
"you can replace <expr> via 'return <expr>;'" );
}
c = INT_INTOBJ(val);
if (c > MAX_DEG_PERM4)
ErrorMayQuit( "Permutation literal exceeds maximum permutatuion degree -- %i vs %i",
c, MAX_DEG_PERM4);

/* if necessary resize the permutation */
if ( SIZE_OBJ(perm)/sizeof(UInt4) < c ) {
Expand Down
5 changes: 5 additions & 0 deletions src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,11 @@ void IntrPermCycle (
(Int)TNAM_OBJ(val), 0L );
}
c = INT_INTOBJ(val);
if (c > MAX_DEG_PERM4)
ErrorQuit( "Permutation literal exceeds maximum permutation degree -- %i vs %i",
c, MAX_DEG_PERM4);



/* if necessary resize the permutation */
if ( SIZE_OBJ(perm)/sizeof(UInt4) < c ) {
Expand Down
17 changes: 15 additions & 2 deletions src/permutat.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "hpc/tls.h"

#include "trans.h"
#include <assert.h>

/****************************************************************************
**
Expand All @@ -97,6 +98,8 @@
*/




/****************************************************************************
**
*F IMAGE(<i>,<pt>,<dg>) . . . . . . image of <i> under <pt> of degree <dg>
Expand Down Expand Up @@ -147,6 +150,7 @@ Obj TmpPerm;
#define TmpPerm TLS(TmpPerm)

static void UseTmpPerm( UInt size) {
assert(size <= MAX_DEG_PERM4);
if (TmpPerm == (Obj)0)
TmpPerm = NewBag(T_PERM4, size);
else if (SIZE_BAG(TmpPerm) < size)
Expand Down Expand Up @@ -2562,6 +2566,10 @@ Obj FuncPermList (

degPerm = LEN_LIST( list );

if (degPerm > MAX_DEG_PERM4)
ErrorMayQuit("PermList: list length %i exceeds maximum permutation degree %i\n",
degPerm, MAX_DEG_PERM4);

/* make sure that the global buffer bag is large enough for checkin*/
UseTmpPerm(degPerm*sizeof(UInt4));

Expand Down Expand Up @@ -3722,6 +3730,9 @@ Obj FuncSHIFTED_PERM (
if (deg<0) deg=0; /* everything shift away */

if (deg>65536) {
if (deg > MAX_DEG_PERM4)
ErrorMayQuit("SHIFTED_PERM: Shift would make permutation degree %i bigger than limit (%i)",
deg, MAX_DEG_PERM4);
to=4;
new=NEW_PERM4(deg);
ptTo2=ADDR_PERM2(new); /* please compiler */
Expand Down Expand Up @@ -4038,8 +4049,7 @@ Obj FunSmallestImgTuplePerm (
UInt lmp; /* largest moved point */
UInt i, k; /* loop variables */

res = 2UL << 30; /* ``infty''.
We have no permutations on over 2^28 points */
res = MAX_DEG_PERM4; /* ``infty''. */
/* handle small permutations */
if ( TNUM_OBJ(perm) == T_PERM2 ) {

Expand Down Expand Up @@ -4455,6 +4465,9 @@ Obj Array2Perm (
"you can replace <expr> via 'return <expr>;'" );
}
c = INT_INTOBJ(val);
if (c > MAX_DEG_PERM4)
ErrorMayQuit( "Permutation literal exceeds maximum permutatuion degree -- %i vs %i",
c, MAX_DEG_PERM4);

/* if necessary resize the permutation */
if ( SIZE_OBJ(perm)/sizeof(UInt4) < c ) {
Expand Down
7 changes: 7 additions & 0 deletions src/permutat.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@

#define IMAGE(i,pt,dg) (((i) < (dg)) ? (pt)[(i)] : (i))

#ifdef SYS_IS_64_BIT
#define MAX_DEG_PERM4 ((1L<<32)-1)
#else
#define MAX_DEG_PERM4 ((1L<<28)-1)
#endif


/****************************************************************************
**
*V IdentityPerm . . . . . . . . . . . . . . . . . . . identity permutation
Expand Down

0 comments on commit 06f20be

Please sign in to comment.