mercurial/cext/revlog.c
changeset 40819 cb372d09d30a
parent 40756 c85964d715fd
parent 40813 884321cd26c3
child 40859 aa76be85029b
equal deleted inserted replaced
40811:e13ab4acf555 40819:cb372d09d30a
   156 	}
   156 	}
   157 
   157 
   158 	return (const char *)(self->buf.buf) + pos * v1_hdrsize;
   158 	return (const char *)(self->buf.buf) + pos * v1_hdrsize;
   159 }
   159 }
   160 
   160 
       
   161 /*
       
   162  * Get parents of the given rev.
       
   163  *
       
   164  * The specified rev must be valid and must not be nullrev. A returned
       
   165  * parent revision may be nullrev, but is guaranteed to be in valid range.
       
   166  */
   161 static inline int index_get_parents(indexObject *self, Py_ssize_t rev, int *ps,
   167 static inline int index_get_parents(indexObject *self, Py_ssize_t rev, int *ps,
   162                                     int maxrev)
   168                                     int maxrev)
   163 {
   169 {
   164 	if (rev >= self->length) {
   170 	if (rev >= self->length) {
   165 		long tmp;
   171 		long tmp;
   178 		ps[0] = getbe32(data + 24);
   184 		ps[0] = getbe32(data + 24);
   179 		ps[1] = getbe32(data + 28);
   185 		ps[1] = getbe32(data + 28);
   180 	}
   186 	}
   181 	/* If index file is corrupted, ps[] may point to invalid revisions. So
   187 	/* If index file is corrupted, ps[] may point to invalid revisions. So
   182 	 * there is a risk of buffer overflow to trust them unconditionally. */
   188 	 * there is a risk of buffer overflow to trust them unconditionally. */
   183 	if (ps[0] > maxrev || ps[1] > maxrev) {
   189 	if (ps[0] < -1 || ps[0] > maxrev || ps[1] < -1 || ps[1] > maxrev) {
   184 		PyErr_SetString(PyExc_ValueError, "parent out of range");
   190 		PyErr_SetString(PyExc_ValueError, "parent out of range");
   185 		return -1;
   191 		return -1;
   186 	}
   192 	}
   187 	return 0;
   193 	return 0;
   188 }
   194 }
  2686                        int inclusive);
  2692                        int inclusive);
  2687 void rustlazyancestors_drop(rustlazyancestorsObject *self);
  2693 void rustlazyancestors_drop(rustlazyancestorsObject *self);
  2688 int rustlazyancestors_next(rustlazyancestorsObject *self);
  2694 int rustlazyancestors_next(rustlazyancestorsObject *self);
  2689 int rustlazyancestors_contains(rustlazyancestorsObject *self, long rev);
  2695 int rustlazyancestors_contains(rustlazyancestorsObject *self, long rev);
  2690 
  2696 
       
  2697 static int index_get_parents_checked(indexObject *self, Py_ssize_t rev, int *ps,
       
  2698                                      int maxrev)
       
  2699 {
       
  2700 	if (rev < 0 || rev >= index_length(self)) {
       
  2701 		PyErr_SetString(PyExc_ValueError, "rev out of range");
       
  2702 		return -1;
       
  2703 	}
       
  2704 	return index_get_parents(self, rev, ps, maxrev);
       
  2705 }
       
  2706 
  2691 /* CPython instance methods */
  2707 /* CPython instance methods */
  2692 static int rustla_init(rustlazyancestorsObject *self, PyObject *args)
  2708 static int rustla_init(rustlazyancestorsObject *self, PyObject *args)
  2693 {
  2709 {
  2694 	PyObject *initrevsarg = NULL;
  2710 	PyObject *initrevsarg = NULL;
  2695 	PyObject *inclusivearg = NULL;
  2711 	PyObject *inclusivearg = NULL;
  2727 
  2743 
  2728 	self->iter = rustlazyancestors_init(index, index_get_parents, linit,
  2744 	self->iter = rustlazyancestors_init(index, index_get_parents, linit,
  2729 	                                    initrevs, stoprev, inclusive);
  2745 	                                    initrevs, stoprev, inclusive);
  2730 	if (self->iter == NULL) {
  2746 	if (self->iter == NULL) {
  2731 		/* if this is because of GraphError::ParentOutOfRange
  2747 		/* if this is because of GraphError::ParentOutOfRange
  2732 		 * index_get_parents() has already set the proper ValueError */
  2748 		 * index_get_parents_checked() has already set the proper
       
  2749 		 * ValueError */
  2733 		goto bail;
  2750 		goto bail;
  2734 	}
  2751 	}
  2735 
  2752 
  2736 	free(initrevs);
  2753 	free(initrevs);
  2737 	return 0;
  2754 	return 0;